G4AxesModel.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 // 
00030 // John Allison  3rd April 2001
00031 // Model which knows how to draw axes.
00032 
00033 #include "G4AxesModel.hh"
00034 
00035 #include "G4ModelingParameters.hh"
00036 #include "G4VGraphicsScene.hh"
00037 #include "G4VisAttributes.hh"
00038 #include "G4Polyline.hh"
00039 #include "G4Colour.hh"
00040 #include "G4UnitsTable.hh"
00041 #include "G4ArrowModel.hh"
00042 #include "G4TextModel.hh"
00043 
00044 G4AxesModel::~G4AxesModel () {}
00045 
00046 G4AxesModel::G4AxesModel
00047 (G4double x0, G4double y0, G4double z0, G4double length,
00048  G4double arrowWidth,
00049  const G4String& colourString,
00050  const G4String& description,
00051  G4bool withAnnotation):
00052   fXAxisModel(0),
00053   fXLabelModel(0),
00054   fXAnnotationModel(0),
00055   fYAxisModel(0),
00056   fYLabelModel(0),
00057   fYAnnotationModel(0),
00058   fZAxisModel(0),
00059   fZLabelModel(0),
00060   fZAnnotationModel(0)
00061 {
00062   fType = "G4AxesModel";
00063   fGlobalTag = fType;
00064   fGlobalDescription = fType + ": " + description;
00065   fExtent = G4VisExtent
00066     (x0, x0+length, y0, y0+length, z0, z0+length);
00067 
00068   G4Colour colour(1,1,1,1);  // Default white and opaque (unless "auto").
00069   G4bool autoColour = false;
00070   if (colourString == "auto") autoColour = true;
00071   else {
00072     if (!G4Colour::GetColour(colourString, colour)) {
00073       G4ExceptionDescription ed;
00074       ed << "Colour \"" << colourString
00075          << "\" not found.  Defaulting to white and opaque.";
00076       G4Exception
00077         ("G4AxesModel::G4AxesModel",
00078          "modeling0012", JustWarning, ed);
00079     }
00080   }
00081 
00082   G4String annotation = G4BestUnit(length,"Length");
00083 
00084   G4Text* text = 0;
00085   G4VisAttributes* va = 0;
00086 
00087   G4Colour xColour(colour);
00088   if (autoColour) xColour = G4Colour::Red();
00089   fXAxisModel = new G4ArrowModel
00090     (x0, y0, z0, x0+length, y0, z0, arrowWidth,
00091      xColour, "x-axis: " + description);
00092   if (withAnnotation) {
00093     text = new G4Text("x",G4Point3D(x0+1.05*length, y0, z0));
00094     text->SetScreenSize(10.);
00095     text->SetLayout(G4Text::centre);
00096     va = new G4VisAttributes(xColour);
00097     text->SetVisAttributes(va);
00098     fXLabelModel = new G4TextModel(*text);
00099     text = new G4Text(annotation,G4Point3D(x0+0.8*length, y0, z0));
00100     text->SetScreenSize(10.);
00101     text->SetOffset(5.,5.);
00102     text->SetLayout(G4Text::centre);
00103     va = new G4VisAttributes(xColour);
00104     text->SetVisAttributes(va);
00105     fXAnnotationModel = new G4TextModel(*text);
00106   }
00107 
00108   G4Colour yColour(colour);
00109   if (autoColour) yColour = G4Colour::Green();
00110   fYAxisModel = new G4ArrowModel
00111     (x0, y0, z0, x0, y0+length, z0, arrowWidth,
00112      yColour, "y-axis: " + description);
00113   if (withAnnotation) {
00114     text = new G4Text("y",G4Point3D(x0, y0+1.05*length, z0));
00115     text->SetScreenSize(10.);
00116     text->SetLayout(G4Text::centre);
00117     va = new G4VisAttributes(yColour);
00118     text->SetVisAttributes(va);
00119     fYLabelModel = new G4TextModel(*text);
00120     text = new G4Text(annotation,G4Point3D(x0, y0+0.8*length, z0));
00121     text->SetScreenSize(10.);
00122     text->SetOffset(5.,5.);
00123     text->SetLayout(G4Text::centre);
00124     va = new G4VisAttributes(yColour);
00125     text->SetVisAttributes(va);
00126     fYAnnotationModel = new G4TextModel(*text);
00127   }
00128 
00129   G4Colour zColour(colour);
00130   if (autoColour) zColour = G4Colour::Blue();
00131   fZAxisModel = new G4ArrowModel
00132     (x0, y0, z0, x0, y0, z0+length, arrowWidth,
00133      zColour, "z-axis: " + description);
00134   if (withAnnotation) {
00135     text = new G4Text("z",G4Point3D(x0, y0, z0+1.05*length));
00136     text->SetScreenSize(10.);
00137     text->SetLayout(G4Text::centre);
00138     va = new G4VisAttributes(zColour);
00139     text->SetVisAttributes(va);
00140     fZLabelModel = new G4TextModel(*text);
00141     text = new G4Text(annotation,G4Point3D(x0, y0, z0+0.8*length));
00142     text->SetScreenSize(10.);
00143     text->SetOffset(5.,5.);
00144     text->SetLayout(G4Text::centre);
00145     va = new G4VisAttributes(zColour);
00146     text->SetVisAttributes(va);
00147     fZAnnotationModel = new G4TextModel(*text);
00148   }
00149 }
00150 
00151 void G4AxesModel::DescribeYourselfTo (G4VGraphicsScene& sceneHandler)
00152 {
00153   if (fXAxisModel)       fXAxisModel->DescribeYourselfTo(sceneHandler);
00154   if (fXLabelModel)      fXLabelModel->DescribeYourselfTo(sceneHandler);
00155   if (fXAnnotationModel) fXAnnotationModel->DescribeYourselfTo(sceneHandler);
00156   if (fYAxisModel)       fYAxisModel->DescribeYourselfTo(sceneHandler);
00157   if (fYLabelModel)      fYLabelModel->DescribeYourselfTo(sceneHandler);
00158   if (fYAnnotationModel) fYAnnotationModel->DescribeYourselfTo(sceneHandler);
00159   if (fZAxisModel)       fZAxisModel->DescribeYourselfTo(sceneHandler);
00160   if (fZLabelModel)      fZLabelModel->DescribeYourselfTo(sceneHandler);
00161   if (fZAnnotationModel) fZAnnotationModel->DescribeYourselfTo(sceneHandler);
00162 }

Generated on Mon May 27 17:47:42 2013 for Geant4 by  doxygen 1.4.7