source: trunk/source/visualization/OpenInventor/src/SoGL2PSAction.cc @ 1051

Last change on this file since 1051 was 1051, checked in by garnier, 15 years ago

qq modifs de debug

  • Property svn:mime-type set to text/cpp
File size: 6.0 KB
Line 
1//
2// ********************************************************************
3// * License and Disclaimer                                           *
4// *                                                                  *
5// * The  Geant4 software  is  copyright of the Copyright Holders  of *
6// * the Geant4 Collaboration.  It is provided  under  the terms  and *
7// * conditions of the Geant4 Software License,  included in the file *
8// * LICENSE and available at  http://cern.ch/geant4/license .  These *
9// * include a list of copyright holders.                             *
10// *                                                                  *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work  make  any representation or  warranty, express or implied, *
14// * regarding  this  software system or assume any liability for its *
15// * use.  Please see the license in the file  LICENSE  and URL above *
16// * for the full disclaimer and the limitation of liability.         *
17// *                                                                  *
18// * This  code  implementation is the result of  the  scientific and *
19// * technical work of the GEANT4 collaboration.                      *
20// * By using,  copying,  modifying or  distributing the software (or *
21// * any work based  on the software)  you  agree  to acknowledge its *
22// * use  in  resulting  scientific  publications,  and indicate your *
23// * acceptance of all terms of the Geant4 Software license.          *
24// ********************************************************************
25//
26#ifdef G4VIS_BUILD_OI_DRIVER
27
28/*----------------------------HEPVis----------------------------------------*/
29/*                                                                          */
30/* Node:             SoGL2PSAction                                          */
31/* Author:           Guy Barrand                                            */
32/*                                                                          */
33/*--------------------------------------------------------------------------*/
34
35// this :
36#include <HEPVis/actions/SoGL2PSAction.h>
37
38// Inventor :
39#include <Inventor/elements/SoViewportRegionElement.h>
40#include <Inventor/errors/SoDebugError.h>
41
42#include "Geant4_gl2ps.h"
43
44#include <stdio.h>
45
46SO_ACTION_SOURCE(SoGL2PSAction)
47//////////////////////////////////////////////////////////////////////////////
48void SoGL2PSAction::initClass(
49)
50//////////////////////////////////////////////////////////////////////////////
51//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
52{
53  SO_ACTION_INIT_CLASS(SoGL2PSAction,SoGLRenderAction);
54}
55//////////////////////////////////////////////////////////////////////////////
56SoGL2PSAction::SoGL2PSAction(
57 const SbViewportRegion& aViewPortRegion
58)
59:SoGLRenderAction(aViewPortRegion)
60,G4OpenGL2PSAction()
61//////////////////////////////////////////////////////////////////////////////
62//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
63{
64  setFileName("out.ps");
65  SO_ACTION_CONSTRUCTOR(SoGL2PSAction);
66}
67
68bool SoGL2PSAction::enableFileWriting(
69)
70//////////////////////////////////////////////////////////////////////////////
71//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
72{
73#ifdef G4DEBUG_VIS_OI
74    printf("SoGL2PSAction::enableFileWriting\n");
75#endif
76  fFile = ::fopen(fFileName,"w");
77  if(!fFile) {
78    SoDebugError::post("SoGL2PSAction::enableFileWriting",
79                       "Cannot open file %s",fFileName);
80    return false;
81  }
82#ifdef __COIN__
83#else //SGI
84  const SbViewportRegion& vpr = getViewportRegion();
85  SoViewportRegionElement::set(getState(),vpr);
86  G4gl2psBegin();
87#endif
88  return true;
89}
90//////////////////////////////////////////////////////////////////////////////
91void SoGL2PSAction::disableFileWriting(
92)
93//////////////////////////////////////////////////////////////////////////////
94//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
95{
96#ifdef __COIN__
97#else //SGI
98  gl2psEndPage();       
99#endif
100  ::fclose(fFile);
101  fFile = 0;
102}
103
104//////////////////////////////////////////////////////////////////////////////
105bool SoGL2PSAction::addBitmap(
106 int aWidth
107,int aHeight
108,float aXorig
109,float aYorig
110,float aXmove
111,float aYmove
112)
113/////////////////////////////////////////////////////////////////////////////
114//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
115{
116  if(!fFile) return false;
117  GLboolean valid;
118  glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID,&valid);
119  if(!valid) return false;
120  float pos[4];
121  glGetFloatv(GL_CURRENT_RASTER_POSITION,pos);
122  int xoff = -(int)(aXmove + aXorig);
123  int yoff = -(int)(aYmove + aYorig);
124  int x = (int)(pos[0] + xoff);
125  int y = (int)(pos[1] + yoff);
126  // Should clip against viewport area :
127  GLint vp[4];
128  glGetIntegerv(GL_VIEWPORT,vp);
129  GLsizei w = aWidth;
130  GLsizei h = aHeight;
131  if(x+w>(vp[0]+vp[2])) w = vp[0]+vp[2]-x;
132  if(y+h>(vp[1]+vp[3])) h = vp[1]+vp[3]-y;
133  int s = 3 * w * h;
134  if(s<=0) return false;
135  float* image = (float*)::malloc(s * sizeof(float));
136  if(!image) return false;
137  glReadPixels(x,y,w,h,GL_RGB,GL_FLOAT,image);
138  GLint status = gl2psDrawPixels(w,h,xoff,yoff,GL_RGB,GL_FLOAT,image);
139  ::free(image);
140  return (status!=GL2PS_SUCCESS ? false : true);
141}
142//////////////////////////////////////////////////////////////////////////////
143void SoGL2PSAction::beginTraversal(
144 SoNode* aNode
145)
146//////////////////////////////////////////////////////////////////////////////
147//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
148{
149  if(fFile) {
150#ifdef __COIN__
151    const SbViewportRegion& vpr = getViewportRegion();
152    SoViewportRegionElement::set(getState(),vpr);
153    G4gl2psBegin();
154    traverse(aNode);
155    gl2psEndPage();       
156#else //SGI
157    // Should have already do G4gl2psBegin() before
158    SoGLRenderAction::beginTraversal(aNode);
159    // Should do gl2psEndPage() after
160#endif
161  } else {
162    SoGLRenderAction::beginTraversal(aNode);
163  }
164}
165
166#endif
Note: See TracBrowser for help on using the repository browser.