Ignore:
Timestamp:
Sep 26, 2007, 12:17:30 PM (17 years ago)
Author:
garnier
Message:

r611@mac-90108: laurentgarnier | 2007-09-26 12:20:44 +0200
dialog ok, en cours en modif du format EPS

Location:
trunk/geant4/visualization
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/geant4/visualization/G4History.macro

    r580 r586  
    5959/gui/addButton viewer "Update scene" "/vis/scene/notifyHandlers"
    6060/N03/event/printModulo 100
     61/run/beamOn 1
  • trunk/geant4/visualization/OpenGL/include/G4OpenGLQtExportDialog.hh

    r585 r586  
    5858  int getWidth();
    5959  int getHeight();
     60  int getTransparency();
     61  int getNbColor();
    6062
    6163public slots:
     
    7476  QPushButton* buttonOk;
    7577  QPushButton* buttonCancel;
    76   //  QButtonGroup* GroupBox1, *GroupBox2;
    77   QCheckBox* boxEPS,*boxTransparency;
     78  QCheckBox* transparencyEPS,*boxTransparency;
    7879  QCheckBox* ratioCheckBox;
    7980  QSlider * qualitySlider;
  • trunk/geant4/visualization/OpenGL/include/G4OpenGLQtViewer.hh

    r585 r586  
    4848#include <QMenu>
    4949#include <QPoint>
     50#include <QImage>
    5051
    5152class G4OpenGLSceneHandler;
     
    7980  void createRadioAction(QAction *,QAction *, const std::string&,unsigned int a=1);
    8081  void rescaleImage(int, int);
    81  
     82  int generateEPS(QString,int,QImage); 
     83
    8284  QMenu *fContextMenu;
    8385  bool fMouseAction; // 1: rotate 0:move
  • trunk/geant4/visualization/OpenGL/src/G4OpenGLQtExportDialog.cc

    r585 r586  
    9292    QVBoxLayout *EPSGroupBoxLayout = new QVBoxLayout;
    9393
    94     boxEPS = new QCheckBox( "boxEPS" );
    95     boxEPS->setText( "save background" );
    96     boxEPS->setChecked( true );
     94    transparencyEPS = new QCheckBox( "transparencyEPS" );
     95    transparencyEPS->setText( "save background" );
     96    transparencyEPS->setChecked( true );
    9797
    9898    color = new QRadioButton("Color");
     
    100100    color->setChecked( true );
    101101    BW->setChecked( false );
    102    
    103     connect( color, SIGNAL( toggled(bool) ), BW, SLOT( setChecked(bool) ) );
    104     connect( BW, SIGNAL( toggled(bool) ), color, SLOT( setChecked(bool) ) );
    105 
    106 
    107     EPSGroupBoxLayout->addWidget(boxEPS);   
     102
     103
     104    EPSGroupBoxLayout->addWidget(transparencyEPS);   
    108105    EPSGroupBoxLayout->addWidget(color);   
    109106    EPSGroupBoxLayout->addWidget(BW);   
     
    157154  ratioCheckBox->setVisible(modify->isChecked());
    158155
    159   connect( original, SIGNAL( toggled(bool) ), modify, SLOT( setChecked(bool) ) );
    160   connect( modify, SIGNAL( toggled(bool) ), original, SLOT( setChecked(bool) ) );
    161   connect( modify, SIGNAL( toggled(bool) ), this, SLOT( changeSizeBox(bool) ) );
     156  connect( original, SIGNAL( clicked(bool) ), this, SLOT( changeSizeBox(true)) );
     157  connect( modify, SIGNAL( clicked(bool) ), this, SLOT( changeSizeBox(false) ) );
    162158
    163159  // height
     
    235231}
    236232
    237 
    238 void G4OpenGLQtExportDialog::changeSizeBox(bool aChange)
    239 {
    240   heightWidget->setVisible(modify->isChecked());
    241   widthWidget->setVisible(modify->isChecked());
    242   ratioCheckBox->setVisible(modify->isChecked());
     233int G4OpenGLQtExportDialog::getTransparency()
     234{
     235  return boxTransparency->isChecked();
     236}
     237
     238int G4OpenGLQtExportDialog::getColorValue()
     239{
     240  if (!color->isChecked())
     241    return 1;
     242  if (color->isChecked() && transparencyEPS->isChecked())
     243    return 4;
     244  return 3;
     245}
     246
     247
     248void G4OpenGLQtExportDialog::changeSizeBox(bool aClick)
     249{
     250  if (aClick) {
     251    modify->toggle();
     252  } else {
     253    original->toggle();
     254  }
     255  if ( original->isChecked()) {
     256    heightWidget->setVisible(false);
     257    widthWidget->setVisible(false);
     258    ratioCheckBox->setVisible(false);
     259  } else {
     260    heightWidget->setVisible(true);
     261    widthWidget->setVisible(true);
     262    ratioCheckBox->setVisible(true);
     263  }
    243264}
    244265
  • trunk/geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc

    r585 r586  
    659659  QList<QByteArray> formats =  QImageWriter::supportedImageFormats ();
    660660  for (int i = 0; i < formats.size(); ++i) {
    661     filters +=formats.at(i);
    662     if ((i+1) <formats.size()) {
    663       filters += ";;";
    664     }
    665   }
     661    filters +=formats.at(i)+";;";
     662    //    if ((i+1) <formats.size()) {
     663    //      filters += ";;";
     664    //    }
     665  }
     666  filters += "eps";
    666667  QString* selectedFilter = new QString();
    667668  QString nomFich =  QFileDialog::getSaveFileName ( GLWindow,
     
    680681   
    681682    printf("rescaling before\n");
    682     QPixmap * pixmap = new QPixmap(fWindow->renderPixmap (exportDialog->getWidth(),exportDialog->getHeight() )) ;//fWindow->grabFrameBuffer();
     683    //    QPixmap * pixmap = new QPixmap(fWindow->renderPixmap (exportDialog->getWidth(),exportDialog->getHeight() )) ;
     684    QImage image = fWindow->grabFrameBuffer();
    683685    printf("rescaling after\n");
    684686     
     687   
    685688    if ((exportDialog->getWidth() !=fWindow->width()) ||
    686689         (exportDialog->getWidth() !=fWindow->width())) {
     
    694697        nomFich.endsWith(".jpeg")) {
    695698      // grabFrameBuffer() :: Returns an image of the frame buffer. If withAlpha is true the alpha channel is included.
    696       pixmap->save(nomFich,0,exportDialog->getSliderValue());
     699      image.save(nomFich,0,exportDialog->getSliderValue());
    697700      printf("saving jpeg quality : %d\n",exportDialog->getSliderValue());
    698701    } else if (nomFich.endsWith(".eps")) {
    699       printf("saving EPS\n");
     702      generateEPS(nomFich,exportDialog->getNbColor(),image);
    700703    } else if (nomFich.endsWith(".tif") ||
    701704               nomFich.endsWith(".tiff") ||
     
    704707               nomFich.endsWith(".bmp") ||
    705708               nomFich.endsWith(".xpm")) {
    706       pixmap->save(nomFich,0,exportDialog->getSliderValue());
     709      image.save(nomFich,0,exportDialog->getSliderValue());
    707710      printf("saving ELSE\n");
    708711    } else {
     
    940943,int aHeight
    941944){
    942   printf("");
     945  printf("should rescale \n");
     946}
     947
     948/**
     949   Generate Postscript form image
     950   @param aFilename : name of file
     951   @param aInColor : numbers of colors : 1->BW 2->RGB 3->RGB+Alpha
     952   @param aImage : Image to print
     953*/
     954int G4OpenGLQtViewer::generateEPS (
     955 QString aFilename
     956,int aInColor
     957,QImage aImage
     958)
     959{
     960 
     961  printf("saving EPS\n");
     962
     963  FILE* fp;
     964 
     965  const uchar * pixels = aImage.bits ();
     966    //  pixels = grabPixels (inColour, width, height);
     967   
     968  if (pixels == NULL)
     969    return 1;
     970 
     971  fp = fopen (aFilename.toStdString().c_str(), "w");
     972  if (fp == NULL) {
     973    return 2;
     974  }
     975 
     976  fprintf (fp, "%%!PS-Adobe-2.0 EPSF-1.2\n");
     977  fprintf (fp, "%%%%Title: %s\n", aFilename.toStdString().c_str());
     978  fprintf (fp, "%%%%Creator: OpenGL pixmap render output\n");
     979  fprintf (fp, "%%%%BoundingBox: 0 0 %d %d\n", fWindow->width(), fWindow->height());
     980  fprintf (fp, "%%%%EndComments\n");
     981  fprintf (fp, "gsave\n");
     982  fprintf (fp, "/bwproc {\n");
     983  fprintf (fp, "    rgbproc\n");
     984  fprintf (fp, "    dup length 3 idiv string 0 3 0 \n");
     985  fprintf (fp, "    5 -1 roll {\n");
     986  fprintf (fp, "    add 2 1 roll 1 sub dup 0 eq\n");
     987  fprintf (fp, "    { pop 3 idiv 3 -1 roll dup 4 -1 roll dup\n");
     988  fprintf (fp, "       3 1 roll 5 -1 roll } put 1 add 3 0 \n");
     989  fprintf (fp, "    { 2 1 roll } ifelse\n");
     990  fprintf (fp, "    }forall\n");
     991  fprintf (fp, "    pop pop pop\n");
     992  fprintf (fp, "} def\n");
     993  fprintf (fp, "systemdict /colorimage known not {\n");
     994  fprintf (fp, "   /colorimage {\n");
     995  fprintf (fp, "       pop\n");
     996  fprintf (fp, "       pop\n");
     997  fprintf (fp, "       /rgbproc exch def\n");
     998  fprintf (fp, "       { bwproc } image\n");
     999  fprintf (fp, "   }  def\n");
     1000  fprintf (fp, "} if\n");
     1001  fprintf (fp, "/picstr %d string def\n", fWindow->width() * aInColor);
     1002  fprintf (fp, "%d %d scale\n", fWindow->width(), fWindow->height());
     1003  fprintf (fp, "%d %d %d\n", fWindow->width(), fWindow->height(), 8);
     1004  fprintf (fp, "[%d 0 0 %d 0 0]\n", fWindow->width(), fWindow->height());
     1005  fprintf (fp, "{currentfile picstr readhexstring pop}\n");
     1006  fprintf (fp, "false %d\n", aInColor);
     1007  //  fprintf (fp, "%%BeginData:       %d ASCII Bytes\n",size);
     1008  fprintf (fp, "colorimage\n");
     1009 
     1010  printf("boucle jusque :%d/%d par ligne:%d \n",fWindow->width()*fWindow->height()*aInColor,aImage.numBytes(),aImage.bytesPerLine ());
     1011
     1012  int pos =0;
     1013  for (int i = 0;i<fWindow->width()*fWindow->height()*aInColor; i++) {
     1014    fprintf (fp, "%02hx ", pixels[i]);
     1015    if (++pos >= aImage.bytesPerLine ()) {
     1016      fprintf (fp, "\n");
     1017      pos = 0;
     1018    }
     1019  }
     1020 
     1021  if (pos)
     1022    fprintf (fp, "\n");
     1023 
     1024  fprintf (fp, "grestore\n");
     1025  fprintf (fp, "showpage\n");
     1026  //  delete pixels;
     1027  fclose (fp);
     1028  return 0;
    9431029}
    9441030#endif
Note: See TracChangeset for help on using the changeset viewer.