Esempio n. 1
0
// Fill the list with face names
void FontSelector::listFontFaces()
{
    FXFontDesc* fonts;
    FXuint      numfonts, f;
    int         selindex = -1;

    familylist->clearItems();
    family->setText("");
    if (FXFont::listFonts(fonts, numfonts, FXString::null, 0, 0, selected.setwidth, selected.encoding, selected.flags))
    {
        FXASSERT(0 < numfonts);
        for (f = 0; f < numfonts; f++)
        {
            familylist->appendItem(fonts[f].face, NULL, (void*)(FXuval)fonts[f].flags);
            if (strcmp(selected.face, fonts[f].face) == 0)
            {
                selindex = f;
            }
        }
        if (selindex == -1)
        {
            selindex = 0;
        }
        if (0 < familylist->getNumItems())
        {
            familylist->setCurrentItem(selindex);
            familylist->makeItemVisible(selindex);
            family->setText(familylist->getItemText(selindex));
            strlcpy(selected.face, familylist->getItemText(selindex).text(), sizeof(selected.face)+1);
        }
        FXFREE(&fonts);
    }
}
Esempio n. 2
0
long
GUISUMOViewParent::onCmdMakeSnapshot(FXObject*,FXSelector,void*) {
    // get the new file name
    FXFileDialog opendialog(this, "Save Snapshot");
    opendialog.setIcon(GUIIconSubSys::getIcon(ICON_EMPTY));
    opendialog.setSelectMode(SELECTFILE_ANY);
    opendialog.setPatternList("All Image Files (*.gif, *.bmp, *.xpm, *.pcx, *.ico, *.rgb, *.xbm, *.tga, *.png, *.jpg, *.jpeg, *.tif, *.tiff)\n"
                              "GIF Image (*.gif)\nBMP Image (*.bmp)\nXPM Image (*.xpm)\nPCX Image (*.pcx)\nICO Image (*.ico)\n"
                              "RGB Image (*.rgb)\nXBM Image (*.xbm)\nTARGA Image (*.tga)\nPNG Image  (*.png)\n"
                              "JPEG Image (*.jpg, *.jpeg)\nTIFF Image (*.tif, *.tiff)\nAll Files (*)");
    if (gCurrentFolder.length()!=0) {
        opendialog.setDirectory(gCurrentFolder);
    }
    if (!opendialog.execute()||!MFXUtils::userPermitsOverwritingWhenFileExists(this, opendialog.getFilename())) {
        return 1;
    }
    gCurrentFolder = opendialog.getDirectory();
    std::string file = opendialog.getFilename().text();
    FXColor *buf = myView->getSnapshot();
    // save
    try {
        MFXImageHelper::saveImage(file, myView->getWidth(), myView->getHeight(), buf);
    } catch (InvalidArgument &e) {
        std::string msg = "Could not save '" + file + "'.\n" + e.what();
        FXMessageBox::error(this, MBOX_OK, "Saving failed.", msg.c_str());
    }
    FXFREE(&buf);
    return 1;
}
Esempio n. 3
0
// Try open file stream
bool FXBZFileStream::open(const FXString& filename,FXStreamDirection save_or_load,FXuval size){
  if(FXFileStream::open(filename,save_or_load,size)){
    if(FXCALLOC(&bz,BZBlock,1)){
      int bzerror;
      bz->stream.next_in=NULL;
      bz->stream.avail_in=0;
      bz->stream.next_out=NULL;
      bz->stream.avail_out=0;
      ac=BZ_RUN;
      if(save_or_load==FXStreamLoad){
        bzerror=BZ2_bzDecompressInit(&bz->stream,VERBOSITY,0);
        if(bzerror==BZ_OK) return true;
        code=FXStreamNoRead;
        }
      else{
        bzerror=BZ2_bzCompressInit(&bz->stream,BLOCKSIZE100K,VERBOSITY,WORKFACTOR);
        if(bzerror==BZ_OK) return true;
        code=FXStreamNoWrite;
        }
      FXFREE(&bz);
      }
    FXFileStream::close();
    }
  return false;
  }
Esempio n. 4
0
// Try open file stream
bool FXGZFileStream::open(const FXString& filename,FXStreamDirection save_or_load,FXuval size){
  if(FXFileStream::open(filename,save_or_load,size)){
    if(FXCALLOC(&z,ZBlock,1)){
      int zerror;
      z->stream.next_in=NULL;
      z->stream.avail_in=0;
      z->stream.next_out=NULL;
      z->stream.avail_out=0;
      f=Z_NO_FLUSH;
      if(save_or_load==FXStreamLoad){
        zerror=inflateInit(&z->stream);
        if(zerror==Z_OK) return true;
        code=FXStreamNoRead;
        }
      else{
        zerror=deflateInit(&z->stream,Z_DEFAULT_COMPRESSION);
        if(zerror==Z_OK) return true;
        code=FXStreamNoWrite;
        }
      FXFREE(&z);
      }
    FXFileStream::close();
    }
  return false;
  }
Esempio n. 5
0
// Close the stream
bool FXMemoryStream::close(){
  if(dir){
    if(owns){FXFREE(&begptr);}
    begptr=NULL;
    wrptr=NULL;
    rdptr=NULL;
    endptr=NULL;
    owns=false;
    return FXStream::close();
    }
  return false;
  }
Esempio n. 6
0
// Give buffer to stream
void FXMemoryStream::giveBuffer(FXuchar *data,FXuval size){
  if(data==NULL){ fxerror("FXMemoryStream::giveBuffer: NULL buffer argument.\n"); }
  if(owns){FXFREE(&begptr);}
  begptr=data;
  endptr=data+size;
  if(dir==FXStreamSave){
    wrptr=begptr;
    rdptr=begptr;
    }
  else{
    wrptr=endptr;
    rdptr=begptr;
    }
  owns=true;
  }
Esempio n. 7
0
// Close file stream
bool FXBZFileStream::close(){
  if(dir){
    if(dir==FXStreamLoad){
      FXFileStream::close();
      BZ2_bzDecompressEnd(&bz->stream);
      }
    else{
      ac=BZ_FINISH;
      FXFileStream::close();
      BZ2_bzCompressEnd(&bz->stream);
      }
    FXFREE(&bz);
    return true;
    }
  return false;
  }
Esempio n. 8
0
// Close file stream
bool FXGZFileStream::close(){
  if(dir){
    if(dir==FXStreamLoad){
      FXFileStream::close();
      inflateEnd(&z->stream);
      }
    else{
      f=Z_FINISH;
      FXFileStream::close();
      deflateEnd(&z->stream);
      }
    FXFREE(&z);
    return true;
    }
  return false;
  }
FXImage*
GUISUMOAbstractView::checkGDALImage(Decal& d) {
#ifdef HAVE_GDAL
    GDALAllRegister();
    GDALDataset* poDataset = (GDALDataset*)GDALOpen(d.filename.c_str(), GA_ReadOnly);
    if (poDataset == 0) {
        return 0;
    }
    const int xSize = poDataset->GetRasterXSize();
    const int ySize = poDataset->GetRasterYSize();
    // checking for geodata in the picture and try to adapt position and scale
    if (d.width <= 0.) {
        double adfGeoTransform[6];
        if (poDataset->GetGeoTransform(adfGeoTransform) == CE_None) {
            Position topLeft(adfGeoTransform[0], adfGeoTransform[3]);
            const double horizontalSize = xSize * adfGeoTransform[1];
            const double verticalSize = ySize * adfGeoTransform[5];
            Position bottomRight(topLeft.x() + horizontalSize, topLeft.y() + verticalSize);
            if (GeoConvHelper::getProcessing().x2cartesian(topLeft) && GeoConvHelper::getProcessing().x2cartesian(bottomRight)) {
                d.width = bottomRight.x() - topLeft.x();
                d.height = topLeft.y() - bottomRight.y();
                d.centerX = (topLeft.x() + bottomRight.x()) / 2;
                d.centerY = (topLeft.y() + bottomRight.y()) / 2;
                //WRITE_MESSAGE("proj: " + toString(poDataset->GetProjectionRef()) + " dim: " + toString(d.width) + "," + toString(d.height) + " center: " + toString(d.centerX) + "," + toString(d.centerY));
            } else {
                WRITE_WARNING("Could not convert coordinates in " + d.filename + ".");
            }
        }
    }
#endif
    if (d.width <= 0.) {
        d.width = getGridWidth();
        d.height = getGridHeight();
    }

    // trying to read the picture
#ifdef HAVE_GDAL
    const int picSize = xSize * ySize;
    FXColor* result;
    if (!FXMALLOC(&result, FXColor, picSize)) {
        WRITE_WARNING("Could not allocate memory for " + d.filename + ".");
        return 0;
    }
    for (int j = 0; j < picSize; j++) {
        result[j] = FXRGB(0, 0, 0);
    }
    bool valid = true;
    for (int i = 1; i <= poDataset->GetRasterCount(); i++) {
        GDALRasterBand* poBand = poDataset->GetRasterBand(i);
        int shift = -1;
        if (poBand->GetColorInterpretation() == GCI_RedBand) {
            shift = 0;
        } else if (poBand->GetColorInterpretation() == GCI_GreenBand) {
            shift = 1;
        } else if (poBand->GetColorInterpretation() == GCI_BlueBand) {
            shift = 2;
        } else if (poBand->GetColorInterpretation() == GCI_AlphaBand) {
            shift = 3;
        } else {
            WRITE_MESSAGE("Unknown color band in " + d.filename + ", maybe fox can parse it.");
            valid = false;
            break;
        }
        assert(xSize == poBand->GetXSize() && ySize == poBand->GetYSize());
        if (poBand->RasterIO(GF_Read, 0, 0, xSize, ySize, ((unsigned char*)result) + shift, xSize, ySize, GDT_Byte, 4, 4 * xSize) == CE_Failure) {
            valid = false;
            break;
        }
    }
    GDALClose(poDataset);
    if (valid) {
        return new FXImage(getApp(), result, IMAGE_OWNED | IMAGE_KEEP | IMAGE_SHMI | IMAGE_SHMP, xSize, ySize);
    }
    FXFREE(&result);
#endif
    return 0;
}
Esempio n. 10
0
std::string
GUISUMOAbstractView::makeSnapshot(const std::string& destFile) {
    std::string errorMessage;
    FXString ext = FXPath::extension(destFile.c_str());
    const bool useGL2PS = ext == "ps" || ext == "eps" || ext == "pdf" || ext == "svg" || ext == "tex" || ext == "pgf";
#ifdef HAVE_FFMPEG
    const bool useVideo = destFile == "" || ext == "h264" || ext == "hevc";
#endif
    for (int i = 0; i < 10 && !makeCurrent(); ++i) {
        FXSingleEventThread::sleep(100);
    }
    // draw
    glClearColor(
        myVisualizationSettings->backgroundColor.red() / 255.,
        myVisualizationSettings->backgroundColor.green() / 255.,
        myVisualizationSettings->backgroundColor.blue() / 255.,
        myVisualizationSettings->backgroundColor.alpha() / 255.);
    glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

    if (myVisualizationSettings->dither) {
        glEnable(GL_DITHER);
    } else {
        glDisable(GL_DITHER);
    }
    if (myVisualizationSettings->antialiase) {
        glEnable(GL_BLEND);
        glEnable(GL_POLYGON_SMOOTH);
        glEnable(GL_LINE_SMOOTH);
    } else {
        glDisable(GL_BLEND);
        glDisable(GL_POLYGON_SMOOTH);
        glDisable(GL_LINE_SMOOTH);
    }

    applyGLTransform();

    if (useGL2PS) {
        GLint format = GL2PS_PS;
        if (ext == "ps") {
            format = GL2PS_PS;
        } else if (ext == "eps") {
            format = GL2PS_EPS;
        } else if (ext == "pdf") {
            format = GL2PS_PDF;
        } else if (ext == "tex") {
            format = GL2PS_TEX;
        } else if (ext == "svg") {
            format = GL2PS_SVG;
        } else if (ext == "pgf") {
            format = GL2PS_PGF;
        } else {
            return "Could not save '" + destFile + "'.\n Unrecognized format '" + std::string(ext.text()) + "'.";
        }
        FILE* fp = fopen(destFile.c_str(), "wb");
        if (fp == 0) {
            return "Could not save '" + destFile + "'.\n Could not open file for writing";
        }
        GLint buffsize = 0, state = GL2PS_OVERFLOW;
        GLint viewport[4];
        glGetIntegerv(GL_VIEWPORT, viewport);
        while (state == GL2PS_OVERFLOW) {
            buffsize += 1024 * 1024;
            gl2psBeginPage(destFile.c_str(), "sumo-gui; http://sumo.dlr.de", viewport, format, GL2PS_SIMPLE_SORT,
                           GL2PS_DRAW_BACKGROUND | GL2PS_USE_CURRENT_VIEWPORT,
                           GL_RGBA, 0, NULL, 0, 0, 0, buffsize, fp, "out.eps");
            glMatrixMode(GL_MODELVIEW);
            glPushMatrix();
            glDisable(GL_TEXTURE_2D);
            glDisable(GL_ALPHA_TEST);
            glDisable(GL_BLEND);
            glEnable(GL_DEPTH_TEST);
            // compute lane width
            // draw decals (if not in grabbing mode)
            if (!myUseToolTips) {
                drawDecals();
                if (myVisualizationSettings->showGrid) {
                    paintGLGrid();
                }
            }
            glLineWidth(1);
            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
            Boundary viewPort = myChanger->getViewport();
            float minB[2];
            float maxB[2];
            minB[0] = viewPort.xmin();
            minB[1] = viewPort.ymin();
            maxB[0] = viewPort.xmax();
            maxB[1] = viewPort.ymax();
            myVisualizationSettings->scale = m2p(SUMO_const_laneWidth);
            glEnable(GL_POLYGON_OFFSET_FILL);
            glEnable(GL_POLYGON_OFFSET_LINE);
            myGrid->Search(minB, maxB, *myVisualizationSettings);

            if (myVisualizationSettings->showSizeLegend) {
                displayLegend();
            }
            state = gl2psEndPage();
            glFinish();
        }
        fclose(fp);
    } else {
        doPaintGL(GL_RENDER, myChanger->getViewport());
        if (myVisualizationSettings->showSizeLegend) {
            displayLegend();
        }
        swapBuffers();
        glFinish();
        FXColor* buf;
        FXMALLOC(&buf, FXColor, getWidth()*getHeight());
        // read from the back buffer
        glReadBuffer(GL_BACK);
        // Read the pixels
        glReadPixels(0, 0, getWidth(), getHeight(), GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)buf);
        makeNonCurrent();
        update();
        // mirror
        size_t mwidth = getWidth();
        size_t mheight = getHeight();
        FXColor* paa = buf;
        FXColor* pbb = buf + mwidth * (mheight - 1);
        do {
            FXColor* pa = paa;
            paa += mwidth;
            FXColor* pb = pbb;
            pbb -= mwidth;
            do {
                FXColor t = *pa;
                *pa++ = *pb;
                *pb++ = t;
            } while (pa < paa);
        } while (paa < pbb);
        try {
#ifdef HAVE_FFMPEG
            if (useVideo) {
                try {
                    saveFrame(destFile, buf);
                    errorMessage = "video";
                } catch (std::runtime_error& err) {
                    errorMessage = err.what();
                }
            } else
#endif
                if (!MFXImageHelper::saveImage(destFile, getWidth(), getHeight(), buf)) {
                    errorMessage = "Could not save '" + destFile + "'.";
                }
        } catch (InvalidArgument& e) {
            errorMessage = "Could not save '" + destFile + "'.\n" + e.what();
        }
        FXFREE(&buf);
    }
    return errorMessage;
}
Esempio n. 11
0
// Fill the list with font sizes
void FontSelector::listFontSizes()
{
    const FXuint sizeint[] =
    {
        60, 80, 90, 100, 110, 120, 140, 160, 200, 240, 300, 360, 420, 480, 640
    };
    FXFontDesc* fonts;
    FXuint      numfonts, f, s, lasts;
    int         selindex = -1;

    sizelist->clearItems();
    size->setText("");
    FXString string;
    if (FXFont::listFonts(fonts, numfonts, selected.face, selected.weight, selected.slant, selected.setwidth, selected.encoding, selected.flags))
    {
        FXASSERT(0 < numfonts);
        lasts = 0;
        if (fonts[0].flags&FXFont::Scalable)
        {
            for (f = 0; f < ARRAYNUMBER(sizeint); f++)
            {
                s = sizeint[f];
                string.format("%.1f", 0.1*s);
                sizelist->appendItem(string, NULL, (void*)(FXuval)s);
                if (selected.size == s)
                {
                    selindex = sizelist->getNumItems()-1;
                }
                lasts = s;
            }
        }
        else
        {
            for (f = 0; f < numfonts; f++)
            {
                s = fonts[f].size;
                if (s != lasts)
                {
                    string.format("%.1f", 0.1*s);
                    sizelist->appendItem(string, NULL, (void*)(FXuval)s);
                    if (selected.size == s)
                    {
                        selindex = sizelist->getNumItems()-1;
                    }
                    lasts = s;
                }
            }
        }
        if (selindex == -1)
        {
            selindex = 0;
        }
        if (0 < sizelist->getNumItems())
        {
            sizelist->setCurrentItem(selindex);
            sizelist->makeItemVisible(selindex);
            size->setText(sizelist->getItemText(selindex));
            selected.size = (FXuint)(FXuval)sizelist->getItemData(selindex);
        }
        FXFREE(&fonts);
    }
}
Esempio n. 12
0
// Fill the list with font slants
void FontSelector::listSlants()
{
    FXFontDesc* fonts;
    FXuint      numfonts, f, s, lasts;
    const char* slt;
    int         selindex = -1;

    stylelist->clearItems();
    style->setText("");
    if (FXFont::listFonts(fonts, numfonts, selected.face, selected.weight, 0, selected.setwidth, selected.encoding, selected.flags))
    {
        FXASSERT(0 < numfonts);
        lasts = 0;
        for (f = 0; f < numfonts; f++)
        {
            s = fonts[f].slant;
            if (s != lasts)
            {
                // Get text for the weight
                switch (s)
                {
                case FXFont::ReverseOblique:
                    slt = "reverse oblique";
                    break;

                case FXFont::ReverseItalic:
                    slt = "reverse italic";
                    break;

                case FXFont::Straight:
                    slt = "regular";
                    break;

                case FXFont::Italic:
                    slt = "italic";
                    break;

                case FXFont::Oblique:
                    slt = "oblique";
                    break;

                default:
                    slt = "normal";
                    break;
                }

                // Add it
                stylelist->appendItem(_(slt), NULL, (void*)(FXuval)s);

                // Remember if this was the current selection
                if (selected.slant == s)
                {
                    selindex = stylelist->getNumItems()-1;
                }
                lasts = s;
            }
        }
        if (selindex == -1)
        {
            selindex = 0;
        }
        if (0 < stylelist->getNumItems())
        {
            stylelist->setCurrentItem(selindex);
            stylelist->makeItemVisible(selindex);
            style->setText(stylelist->getItemText(selindex));
            selected.slant = (FXuint)(FXuval)stylelist->getItemData(selindex);
        }
        FXFREE(&fonts);
    }
}
Esempio n. 13
0
// Fill the list with font weights
void FontSelector::listWeights()
{
    FXFontDesc* fonts;
    FXuint      numfonts, f, ww, lastww;
    const char* wgt;
    int         selindex = -1;

    weightlist->clearItems();
    weight->setText("");
    if (FXFont::listFonts(fonts, numfonts, selected.face, 0, 0, selected.setwidth, selected.encoding, selected.flags))
    {
        FXASSERT(0 < numfonts);
        lastww = 0;
        for (f = 0; f < numfonts; f++)
        {
            ww = fonts[f].weight;
            if (ww != lastww)
            {
                // Get text for the weight
                switch (ww)
                {
                case FXFont::Thin:
                    wgt = "thin";
                    break;

                case FXFont::ExtraLight:
                    wgt = "extra light";
                    break;

                case FXFont::Light:
                    wgt = "light";
                    break;

                case FXFont::Normal:
                    wgt = "normal";
                    break;

                case FXFont::Medium:
                    wgt = "medium";
                    break;

                case FXFont::DemiBold:
                    wgt = "demibold";
                    break;

                case FXFont::Bold:
                    wgt = "bold";
                    break;

                case FXFont::ExtraBold:
                    wgt = "extra bold";
                    break;

                case FXFont::Black:
                    wgt = "black";
                    break;

                default:
                    wgt = "normal";
                    break;
                }

                // Add it
                weightlist->appendItem(_(wgt), NULL, (void*)(FXuval)ww);

                // Remember if this was the current selection
                if (selected.weight == ww)
                {
                    selindex = weightlist->getNumItems()-1;
                }
                lastww = ww;
            }
        }
        if (selindex == -1)
        {
            selindex = 0;
        }
        if (0 < weightlist->getNumItems())
        {
            weightlist->setCurrentItem(selindex);
            weightlist->makeItemVisible(selindex);
            weight->setText(weightlist->getItemText(selindex));
            selected.weight = (FXuint)(FXuval)weightlist->getItemData(selindex);
        }
        FXFREE(&fonts);
    }
}