示例#1
0
void WInputDialog::initialize() {
/*******************************/

    WPoint avg;
    WPoint max;
    textMetrics( avg, max );
    int sp = max.x();

    int x = WSystemMetrics::dialogFrameWidth();
    int y = WSystemMetrics::dialogFrameHeight();

    int p_w = 0;
    int p_h = 0;
    updateExtents( _promptText, &p_w, &p_h );
    p_w += avg.x() / 2;
    p_h += avg.y() / 2;
    int r_w = 32 * avg.x();
    int r_h = max.y() + 2*max.y() / 3;
    updateExtents( *_reply, &r_w, &r_h );

    _prompt = new WText( this, WRect( x, y + (r_h - p_h)/2, p_w, p_h ), _promptText );
    _prompt->show();
    _input = new WEditBox( this, WRect( x + p_w + sp, y, r_w, r_h ), *_reply );
    _input->show();
    y += p_h + max.y();

    int b_w = 0;
    int b_h = 0;
    updateExtents( BrowseText, &b_w, &b_h );
    updateExtents( CancelText, &b_w, &b_h );
    updateExtents( OKText, &b_w, &b_h );
    b_w += avg.x() * 2;
    b_h += avg.y() / 2;
    WDefPushButton *bOk = new WDefPushButton( this, WRect( x, y, b_w, b_h ),
                                              OKText );
    bOk->onClick( this, (cbw)&WInputDialog::okButton );
    bOk->show();
    x += b_w + max.x();

    WPushButton *bCancel = new WPushButton( this, WRect( x, y, b_w, b_h ),
                                            CancelText );
    bCancel->onClick( this, (cbw)&WInputDialog::cancelButton );
    bCancel->show();
    x += b_w + max.x();

    if( _browseDialog ) {
        WPushButton *bBrowse = new WPushButton( this,
                                                WRect( x, y, b_w, b_h ),
                                                BrowseText );
        bBrowse->onClick( this, (cbw)&WInputDialog::browseButton );
        bBrowse->show();
    }

    shrink();
    centre();

    _input->select();
    _input->setFocus();
    show();
}
bool ossimPlanetTextureLayerGroup::hasTexture(ossim_uint32 width,
                                              ossim_uint32 height,
                                              const ossimPlanetTerrainTileId& tileId,
                                              const ossimPlanetGrid& grid)
{
   if(!theEnableFlag)
   {
      return false;
   }
   if(tileId.level() == 0) return true;

   if(theDirtyExtentsFlag)
   {
      updateExtents();
   }
   
   if(theExtents.valid())
   {
      osg::ref_ptr<ossimPlanetExtents> extents = new ossimPlanetExtents;
      if(grid.convertToGeographicExtents(tileId, *extents, width, height))
      {
         if(!theExtents->intersectsLatLon(*extents)&&
            !theExtents->intersectsScale(*extents))
         {
            return false;
         }
      }
   }
   else
   {
      return false;
   }
   
   bool result = false;
   ossim_uint32 idx = 0;
   for(idx = 0; ((idx < theChildrenList.size())&&!result); ++idx)
   {
      if(theChildrenList[idx]->hasTexture(width, height, tileId, grid))
      {
         result = true;
      }
   }
   return result;
}
示例#3
0
void WAutoDialog::initialize() {
    /******************************/

    WText       *t;
    WPoint      avg;
    WPoint      max;
    int         i;

    setSystemFont( FALSE );
    int x = WSystemMetrics::dialogFrameWidth();
    int y = WSystemMetrics::dialogFrameHeight();
    textMetrics( avg, max );

    int t_w = 0;
    int t_h = 0;
    int icount = _prompts->count();
    for( i = 0; i < icount; i++ ) {
        updateExtents( _prompts->cStringAt( i ), &t_w, &t_h );
    }

    int b_w = 50 * avg.x() / 4;
    int b_h = 14 * avg.y() / 8;

    int p_w = _editwidth * avg.x();
    int p_h = max.y();
    t_w += avg.x() / 2;
    t_h += avg.y() / 2;
    p_w += avg.x() / 2;
    p_h += 2*max.y() / 3;
    int sp = max.x();

    for( i = 0; i < icount; i++ ) {
        WString s( _prompts->cStringAt( i ) );
        bool bro = FALSE;
        char* p = strchr( (char *)s.gets(), '=' );
        if( p != NULL ) { // this code depends on internals of WString!
            *p = '\0';
            p++;
            if( *p == '=' ) {
                bro = TRUE;
                p++;
            }
        }
        t = new WText( this, WRect( x, y + (p_h - t_h)/2, t_w, t_h ), s );
        t->show();
        WEditBox* e = new WEditBox( this,
                                    WRect( x + t_w + sp, y, p_w, p_h ), p );
        e->show();
        _inputs.add( e );
        if( bro ) {
            WPushButton* bBrowse = new WPushButton( this,
                                                    WRect( x + t_w + p_w + 2*sp, y, b_w, b_h ), BrowseText );
            bBrowse->onClick( this, (cbw)&WAutoDialog::browseButton );
            bBrowse->setTagPtr( e );
            bBrowse->show();
        }
        y += t_h + t_h / 2;
    }

    WDefPushButton* bOk = new WDefPushButton( this, WRect( x, y, b_w, b_h ),
            OKText );
    bOk->onClick( this, (cbw)&WAutoDialog::okButton );
    bOk->show();

    WPushButton* bCancel = new WPushButton( this,
                                            WRect( x + b_w + sp, y, b_w, b_h ), CancelText );
    bCancel->onClick( this, (cbw)&WAutoDialog::cancelButton );
    bCancel->show();

    shrink();
    centre();

    WEditBox* e = (WEditBox *)_inputs[0];
    e->select();
    e->setFocus();
    show();
}
osg::ref_ptr<ossimPlanetImage> ossimPlanetTextureLayerGroup::getTexture(ossim_uint32 level,
                                                                        ossim_uint64 row,
                                                                        ossim_uint64 col,
                                                                        const ossimPlanetGridUtility& utility)
{
   if(!theEnableFlag)
   {
      return 0;
   }
   if(theDirtyExtentsFlag)
   {
      updateExtents();
   }
   OpenThreads::ScopedLock<OpenThreads::Mutex> lock(theChildrenListMutex);

   ossim_uint32 idx = 0;
   osg::ref_ptr<ossimPlanetImage> result;
   double minLat;
   double minLon;
   double maxLat;
   double maxLon;
//   unsigned int w = utility.getTileWidth();
   unsigned int h = utility.getTileHeight();

   utility.getLatLonBounds(minLat,
                           minLon,
                           maxLat,
                           maxLon,
                           level,
                           row, 
                           col );
   if(!theExtents->intersectsLatLon(minLat, minLon, maxLat, maxLon))
   {
      return 0;
   }
   double deltaX;
   double deltaY;
   utility.getWidthHeightInDegrees(deltaX, deltaY, level, row, col);
   
   double deltaLat    = deltaY/h;
//   double deltaLon    = deltaX/w;
   ossimDpt gsd = ossimGpt().metersPerDegree();
   gsd.y *= deltaLat;
   if(gsd.y>theExtents->getMaxScale())//!theExtents->intersectsScale(gsd.y,
       //                            gsd.y))
   {
      return 0;
   }
      
   for(idx = 0; idx < theChildrenList.size(); ++idx)
   {
      if(theChildrenList[idx].valid())
      {
         const osg::ref_ptr<ossimPlanetExtents> extents = theChildrenList[idx]->getExtents();
         
         if(extents->intersectsLatLon(minLat, minLon, maxLat, maxLon))
         {
            osg::ref_ptr<ossimPlanetImage> image = theChildrenList[idx]->getTexture(level, row, col, utility);
            if(image.valid())
            {
               if(result.valid())
               {
                  mergeImage(image.get(), result.get());
                  result = image;
                  result->setPixelStatus();
                  if(result->getPixelStatus() == ossimPlanetImage::ossimPlanetImagePixelStatus_FULL)
                  {
                     return result;
                  }
               }
               else
               {
                  result = (ossimPlanetImage*)image->clone(osg::CopyOp::DEEP_COPY_ALL);
                  if(result->getPixelStatus() == ossimPlanetImage::ossimPlanetImagePixelStatus_FULL)
                  {
                     return result;
                  }
               }
            }
         }
      }
   }
   
   return result;
}
osg::ref_ptr<ossimPlanetImage> ossimPlanetTextureLayerGroup::getTexture(ossim_uint32 width,
                                                                        ossim_uint32 height,
                                                                        const ossimPlanetTerrainTileId& tileId,
                                                                        const ossimPlanetGrid& grid,
                                                                        ossim_int32 padding)
{
   if(!theEnableFlag)
   {
      return 0;
   }
   if(theDirtyExtentsFlag)
   {
      updateExtents();
   }
   OpenThreads::ScopedLock<OpenThreads::Mutex> lock(theChildrenListMutex);
   osg::ref_ptr<ossimPlanetExtents> tileExtents = new ossimPlanetExtents;
   if(grid.convertToGeographicExtents(tileId, *tileExtents, width, height))
   {
      if(theExtents.valid())
      {
         if(!theExtents->intersectsLatLon(*tileExtents)&&
            !theExtents->intersectsScale(*tileExtents))
         {
            return 0;
         }
      }
   }
   ossim_uint32 idx = 0;
   osg::ref_ptr<ossimPlanetImage> result;
   ossim_float32 opacity = 1.0;
   if(theChildrenList.size() == 1)
   {
     result = theChildrenList[idx]->getTexture(width, height, tileId, grid);
   }
   else
   {
     for(idx = 0; idx < theChildrenList.size(); ++idx)
     {
        if(theChildrenList[idx].valid()&&(theChildrenList[idx]->opacity() > 0.0))
        {
           osg::ref_ptr<ossimPlanetImage> image = theChildrenList[idx]->getTexture(width, height, tileId, grid);

           if(image.valid())
           {

             ossimPlanetImage::ossimPlanetImagePixelStatus pixelStatus = image->getPixelStatus();
              if(result.valid())
              {
                // use previous opacity for merging
                 //mergeImage(image.get(), result.get(), 1.0 - opacity);
                 mergeImage(image.get(), result.get(), opacity);
                 // update opacity
                 opacity = theChildrenList[idx]->opacity();
                 result = image;
                 result->getPixelStatus();
                 pixelStatus = result->getPixelStatus();
                 if((pixelStatus == ossimPlanetImage::ossimPlanetImagePixelStatus_FULL)&&
                     (opacity == 1.0))
                 {
                   // we are finished
                    break;
                 }
              }
              else
              {
                opacity = theChildrenList[idx]->opacity();
                if((opacity == 1.0) &&
                    (pixelStatus == ossimPlanetImage::ossimPlanetImagePixelStatus_FULL))
                {
                  result = image;
                  break;
                }
                else
                {
                  result = (ossimPlanetImage*)image->clone(osg::CopyOp::DEEP_COPY_ALL);
                }
              }// end if result.valid()
           }// end if image.valid()
        }
     }
   }
   if(result.get())
   {
      result = applyBrightnessContrast(result.get(), true);
   }
   if((!result.valid()&&((ossim_int32)tileId.level()<=theFillEmptyNullTileMaxLevel))||
      (result.valid()&&result->getPixelStatus()==ossimPlanetImage::ossimPlanetImagePixelStatus_EMPTY))
   {
      ossim_uint32 area = width*height;
      unsigned char* newData = new unsigned char[area*4];
      ossim_uint8 r = static_cast<ossim_uint8>(theBackgroundColor[0]*255);
      ossim_uint8 g = static_cast<ossim_uint8>(theBackgroundColor[1]*255);
      ossim_uint8 b = static_cast<ossim_uint8>(theBackgroundColor[2]*255);
      ossim_uint8 a = static_cast<ossim_uint8>(theBackgroundColor[3]*255);
      if(r==g&&r==b&&r==a)
      {
         memset(newData, r, area*4);
      }
      else
      {
         ossim_uint32 idx = 0;
         unsigned char* newDataPtr = newData;
         for(idx = 0; idx < area; ++idx,newDataPtr+=4)
         {
            newDataPtr[0] = r;
            newDataPtr[1] = g;
            newDataPtr[2] = b;
            newDataPtr[3] = a;
         }
      }
      result = new ossimPlanetImage();
      result->setImage(width, height, 1,
                        GL_RGBA,
                        GL_RGBA,
                        GL_UNSIGNED_BYTE,
                        newData,
                       osg::Image::USE_NEW_DELETE);
   }
   else if(result.valid()&&theFillTranslucentPixelsWithBackgroundEnabled)
   {
      ossimPlanetImage::ossimPlanetImagePixelStatus pixelStatus = result->getPixelStatus();
      if(pixelStatus != ossimPlanetImage::ossimPlanetImagePixelStatus_FULL)
      {
         unsigned char* dataPtr = result->data();
         ossim_uint32 area = result->width()*result->height();
         ossim_uint32 idx = 0;
         ossim_uint8 r = static_cast<ossim_uint8>(theBackgroundColor[0]*255);
         ossim_uint8 g = static_cast<ossim_uint8>(theBackgroundColor[1]*255);
         ossim_uint8 b = static_cast<ossim_uint8>(theBackgroundColor[2]*255);
         ossim_uint8 a = static_cast<ossim_uint8>(theBackgroundColor[3]*255);
         for(idx = 0; idx < area;++idx,dataPtr+=4)
         {
            if(dataPtr[3] < 1)
            {
               dataPtr[0] = r;
               dataPtr[1] = g;
               dataPtr[2] = b;
               dataPtr[3] = a;
            }
         }
         result->setPixelStatus();
      }

   }
   return result;
}