// // $Id: ToyDraw.cpp,v 1.6 2005/12/16 21:34:27 snyder Exp $ // // File: draw.cpp // Purpose: Simple transverse plane event display for debugging // Created: 01-JUN-1998 John Hobbs // // $Revision: 1.6 $ // // // Include files #include "ToyDraw.hpp" #include "spacegeom/SpacePoint.h" #include "geometry_system/components/CartesianCoordinate.hpp" #include "silicon_geometry/base/SiBarrel.hpp" using namespace std; using namespace dgs; static int pageid; static const float myPI(3.1415927); // Global definitions void draw_init(std::ostream& os) { pageid=0; os << "%!PS-Adobe-2.0" << endl; os << "%%Creator: silicon_geometry" << endl; os << "%%Title: SMT geometry" << endl; os << "%%Pages: 6" << endl; os << "%%PageOrder: Ascend" << endl; os << "%%EndComments" << endl; os << "/s {stroke} def" << endl; os << "/l {lineto} def" << endl; os << "/m {moveto} def" << endl; os << "/d {rlineto} def" << endl; os << "/r {rmoveto} def" << endl; os << "/cl {closepath} def" << endl; os << "/sf {scalefont setfont} def" << endl; os << "/c {setrgbcolor} def" << endl; os << "/black {0 setgray} def" << endl; os << "/lw {setlinewidth} def" << endl; os << "gsave" << endl; } void draw_done(std::ostream &os) { os << "grestore" << endl; os << "%%EOF" << endl; } void draw_arc(std::ostream& os, double xc, double yc, double r, double phimin, double phimax) { os << "newpath " << xc << " " << yc << " " << r << " " << phimin << " " << phimax << " arc s" << endl; } void draw_axis(std::ostream &os, SpacePoint start, SpacePoint stop) { if( start == stop ) return; double dx = stop.x()-start.x(); double dy = stop.y()-start.y() ; double r = sqrt(dx*dx+dy*dy); double ra = 0.2*r; double alpha = atan2(dy,dx); double sa = sin(alpha); double ca = cos(alpha); draw_setcolor(os,1.0,0.0,0.0); os << start.x() << " " << start.y() << " m " << stop.x() << " " << stop.y() << " l " << ra*(-ca+sa) << " " << -ra*(sa+ca) << " d " << -2.0*ra*sa << " " << 2.0*ra*ca << " d " << ra*(ca-sa) << " " << -ra*(sa+ca) << " d " << "s " << endl; draw_setblack(os); } void draw_newpage(std::ostream &os, const double scale) { // Set up the drawing double centerx = 306.0/scale; double centery = 396.0/scale; ++pageid; os << "%%Page: " << pageid << " " << pageid << endl; os << "gsave " << scale << " " << scale << " scale " << centerx << " " << centery << " translate" << endl; } void draw_endpage(std::ostream &os) { os << "showpage grestore" << endl; } void draw_setcolor(std::ostream& os, const double red, const double green, const double blue) { os << " " << red << " " << green << " " << blue << " c" <get_radius(); draw_setcolor(os,0.5,0.5,0.5); os << "0.02 lw" << endl; os << "newpath 0 0 " << r1 << " 0 360 arc s" << endl; draw_setblack(os); os << "0.05 lw" << endl; // Draw the ladders (end view) for( int ilad=1 ; ilad<=(layer->get_ladder_count()) ; ilad++ ) { const SiLadder* ladder = layer->get_ladder(ilad); double xmin = ladder->get_xsize(); CartesianCoordinate x0(-xmin,0.0,0.0); CartesianCoordinate x1(xmin,0.0,0.0); // Draw the ladder itself SpacePoint ladstart = ladder->local_to_global(x0); SpacePoint ladstop = ladder->local_to_global(x1); //cout << "GPStart: " << ladstart << ", Half width = " << xmin << endl; //cout << "GPStop: " << ladstop << endl; os << " " << ladstart.x() << " " << ladstart.y() << " m " << ladstop.x() << " " << ladstop.y() << " l s " << endl; // Draw the positive and negative x ends SpacePoint textm = ladder->local_to_global(x0); SpacePoint textp = ladder->local_to_global(x1); os << "1 0 0 c /Times-Roman findfont 0.6 sf " << textm.x() << " " << textm.y() << " m (-) show " << textp.x() << " " << textp.y() << " m (+) show black" << endl; // For first ladder, also draw the z-axis orientation SpacePoint gorigin = ladder->local_to_global(origin); if( ilad==1 ) { CartesianCoordinate z1(0.0,0.5,0.0); SpacePoint zunit = ladder->local_to_global(z1); //os << "% Arrow in next line" << endl; draw_axis(os,gorigin,zunit); } // Keep the largest radius for use in writing label. double xmax=gorigin.x(),ymax=gorigin.y(); double r=sqrt(xmax*xmax+ymax*ymax); if( r>rmax ) rmax=r; } } // Write the barrel information... double textx=1.2*(0.500*rmax); double texty=1.2*(0.866*rmax); os << "/Times-Roman findfont 1.0 sf " << endl; if( idb>=0 ) os << textx << " " << texty << " m (Barrel " << idb << ") show" << endl; os << textx << " " << 0.9*texty << " m (z = " << barrel.z() << ") show" << endl; return true; } bool draw_object(std::ostream& os, const SiBulkhead& sibh, const int idb) // // Purpose: Draw an end view of the given bulkhead // { draw_setcolor(os,1.0,0.0,1.0); os << "0.02 lw" << endl; int nlayers = sibh.get_layer_count(); for( int i=1 ; i<=nlayers ; i++ ) { const SiBulkheadElement* layer = sibh.get_layer(i); int nsides = layer->get_sides(); // The inner edge. float lmin = layer->get_inner_length(); float rmin = layer->get_inner_radius(); float x = rmin; float y = -lmin/2.0; float phi = 0.0; float dphi = (2.0*myPI)/(float)nsides; SpacePoint lpt = layer->local_to_global(CartesianCoordinate(x,y,0.0)); os << "newpath " << lpt.x() << " " << lpt.y() << " m"<< endl; // Inner edge, draw this one clockwise, so that 'fill' below works... for( int is=0 ; islocal_to_global(CartesianCoordinate(x,y,0.0)); os << " " << lpt.x() << " " << lpt.y() << " l "; if( is != (nsides-1) ) os << endl; } os << endl; // The outer edge float lmax = layer->get_outer_length(); float rmax = layer->get_outer_radius(); x = rmax; y = -lmax/2.0; phi = 0.0; lpt = layer->local_to_global(CartesianCoordinate(x,y,0.0)); os << " " << lpt.x() << " " << lpt.y() << " m"<< endl; for( int iso=0 ; isolocal_to_global(CartesianCoordinate(x,y,0.0)); os << " " << lpt.x() << " " << lpt.y() << " l "; if( iso != (nsides-1) ) os << endl; phi = phi+dphi; } os << "fill" << endl; } draw_setblack(os); os << "0.05 lw" << endl; return true; } bool draw_object(std::ostream& os, SiTrough& trough) // // Purpose: Draw an end view of the support trough // { // Get the necessary coordinates... float radius = trough.get_radius(); // float dphi = (180.0/3.1415927)*trough.get_dphi(); float dphi = 180.0; // and do the drawing (for now, assume it's centered at (0,0))... draw_setcolor(os,1.0,0.0,1.0); os << "0.02 lw" << endl; os << "newpath 0 0 " << radius << " " << dphi << " 0 arc s" << endl; draw_setblack(os); os << "0.05 lw" << endl; return true; }