G4OpenGLXmViewerMessenger.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 #ifdef G4VIS_BUILD_OPENGLXM_DRIVER
00030 
00031 #include "G4OpenGLXmViewerMessenger.hh"
00032 
00033 #include "G4SystemOfUnits.hh"
00034 #include "G4OpenGLXmViewer.hh"
00035 #include "G4OpenGLXmSliderBar.hh"
00036 
00037 #include "G4UImanager.hh"
00038 #include "G4UIcommand.hh"
00039 #include "G4UIdirectory.hh"
00040 #include "G4UIcmdWithADoubleAndUnit.hh"
00041 #include "G4UIcmdWithADouble.hh"
00042 
00043 #include "G4VisManager.hh"
00044 
00045 G4OpenGLXmViewerMessenger* G4OpenGLXmViewerMessenger::fpInstance = 0;
00046 
00047 G4OpenGLXmViewerMessenger* G4OpenGLXmViewerMessenger::GetInstance()
00048 {
00049   if (!fpInstance) fpInstance = new G4OpenGLXmViewerMessenger;
00050   return fpInstance;
00051 }
00052 
00053 G4OpenGLXmViewerMessenger::G4OpenGLXmViewerMessenger()
00054 {
00055   G4bool omitable;
00056 
00057   fpDirectory = new G4UIdirectory("/vis/oglxm/");
00058   fpDirectory->SetGuidance("G4OpenGLXmViewer commands.");
00059 
00060   fpDirectorySet = new G4UIdirectory ("/vis/oglxm/set/");
00061   fpDirectorySet->SetGuidance("G4OpenGLXmViewer set commands.");
00062 
00063   fpCommandSetDollyHigh =
00064     new G4UIcmdWithADoubleAndUnit("/vis/oglxm/set/dolly-high", this);
00065   fpCommandSetDollyHigh->SetGuidance("Higher limit of dolly slider.");
00066   fpCommandSetDollyHigh->SetParameterName("dolly-high", omitable = false);
00067 
00068   fpCommandSetDollyLow =
00069     new G4UIcmdWithADoubleAndUnit("/vis/oglxm/set/dolly-low", this);
00070   fpCommandSetDollyLow->SetGuidance("Lower limit of dolly slider.");
00071   fpCommandSetDollyLow->SetParameterName("dolly-low", omitable = false);
00072 
00073   fpCommandSetPanHigh =
00074     new G4UIcmdWithADoubleAndUnit("/vis/oglxm/set/pan-high", this);
00075   fpCommandSetPanHigh->SetGuidance("Higher limit of pan slider.");
00076   fpCommandSetPanHigh->SetParameterName("pan-high", omitable = false);
00077 
00078   fpCommandSetRotationHigh =
00079     new G4UIcmdWithADoubleAndUnit("/vis/oglxm/set/rotation-high", this);
00080   fpCommandSetRotationHigh->SetGuidance("Higher limit of rotation slider.");
00081   fpCommandSetRotationHigh->SetParameterName("rotation-high", omitable = false);
00082 
00083   fpCommandSetZoomHigh =
00084     new G4UIcmdWithADouble("/vis/oglxm/set/zoom-high", this);
00085   fpCommandSetZoomHigh->SetGuidance("Higher limit of zoom slider.");
00086   fpCommandSetZoomHigh->SetParameterName("zoom-high", omitable = false);
00087 
00088   fpCommandSetZoomLow =
00089     new G4UIcmdWithADouble("/vis/oglxm/set/zoom-low", this);
00090   fpCommandSetZoomLow->SetGuidance("Lower limit of zoom slider.");
00091   fpCommandSetZoomLow->SetParameterName("zoom-low", omitable = false);
00092 }
00093 
00094 G4OpenGLXmViewerMessenger::~G4OpenGLXmViewerMessenger ()
00095 {
00096   delete fpCommandSetZoomLow;
00097   delete fpCommandSetZoomHigh;
00098   delete fpCommandSetRotationHigh;
00099   delete fpCommandSetPanHigh;
00100   delete fpCommandSetDollyLow;
00101   delete fpCommandSetDollyHigh;
00102   delete fpDirectorySet;
00103   delete fpDirectory;
00104 }
00105 
00106 void G4OpenGLXmViewerMessenger::SetNewValue
00107 (G4UIcommand* command, G4String newValue)
00108 {
00109   G4VisManager* pVisManager = G4VisManager::GetInstance();
00110 
00111   G4VViewer* pVViewer = pVisManager->GetCurrentViewer();
00112 
00113   if (!pVViewer) {
00114     G4cout <<
00115       "G4OpenGLXmViewerMessenger::SetNewValue: No current viewer."
00116       "\n  \"/vis/open\", or similar, to get one."
00117            << G4endl;
00118     return;
00119   }
00120 
00121   G4OpenGLXmViewer* pViewer = dynamic_cast<G4OpenGLXmViewer*>(pVViewer);
00122 
00123   if (!pViewer) {
00124     G4cout <<
00125       "G4OpenGLXmViewerMessenger::SetNewValue: Current viewer is not of type"
00126       "\n  OGLIXm or OGLSXm.  Use \"/vis/viewer/select\" or \"/vis/open\"."
00127            << G4endl;
00128     return;
00129   }
00130 
00131   G4bool panningControlPanel = true;
00132   G4bool rotationControlPanel = true;
00133 
00134   if (command == fpCommandSetDollyHigh)
00135     {
00136       if (pViewer->fpdolly_slider)
00137         {
00138           pViewer->dolly_high =
00139             fpCommandSetDollyHigh->GetNewDoubleValue(newValue);
00140           pViewer->fpdolly_slider->SetMaxValue (pViewer->dolly_high);
00141           if (pViewer->fVP.GetDolly() > pViewer->dolly_high)
00142             {
00143               pViewer->fpdolly_slider->SetInitialValue (pViewer->dolly_high);
00144               pViewer->fVP.SetDolly(pViewer->dolly_high);
00145             }
00146           else
00147             {
00148               pViewer->fpdolly_slider->SetInitialValue (pViewer->fVP.GetDolly());
00149             }
00150         }
00151       else
00152         {
00153           panningControlPanel = false;
00154         }
00155     }
00156 
00157   else if (command == fpCommandSetDollyLow)
00158     {
00159       if (pViewer->fpdolly_slider)
00160         {
00161           pViewer->dolly_low =
00162             fpCommandSetDollyLow->GetNewDoubleValue(newValue);
00163           pViewer->fpdolly_slider->SetMinValue (pViewer->dolly_low);
00164           if (pViewer->fVP.GetDolly() < pViewer->dolly_low)
00165             {
00166               pViewer->fpdolly_slider->SetInitialValue (pViewer->dolly_low);
00167               pViewer->fVP.SetDolly(pViewer->dolly_low);
00168             }
00169           else
00170             {
00171               pViewer->fpdolly_slider->SetInitialValue (pViewer->fVP.GetDolly());
00172             }
00173         }
00174       else
00175         {
00176           panningControlPanel = false;
00177         }
00178     }
00179 
00180   else if (command == fpCommandSetPanHigh)
00181     {
00182       if (pViewer->fppanning_slider)
00183         {
00184           pViewer->pan_sens_limit =
00185             fpCommandSetPanHigh->GetNewDoubleValue(newValue);
00186           pViewer->fppanning_slider->SetMaxValue (pViewer->pan_sens_limit);
00187           pViewer->fppanning_slider->SetInitialValue (pViewer->pan_sens_limit / 2.);
00188         }
00189       else
00190         {
00191           panningControlPanel = false;
00192         }
00193     }
00194 
00195   else if (command == fpCommandSetRotationHigh)
00196     {
00197       if (pViewer->fprotation_slider)
00198         {
00199           // Internally in OpenGLXm, it's in degrees...
00200           pViewer->rot_sens_limit =
00201             fpCommandSetRotationHigh->GetNewDoubleValue(newValue) / deg;
00202           pViewer->fprotation_slider->SetMaxValue (pViewer->rot_sens_limit);
00203           pViewer->fprotation_slider->SetInitialValue (pViewer->rot_sens_limit / 2.);
00204         }
00205       else
00206         {
00207           rotationControlPanel = false;
00208         }
00209     }
00210 
00211   else if (command == fpCommandSetZoomHigh)
00212     {
00213       if (pViewer->fpzoom_slider)
00214         {
00215           pViewer->zoom_high =
00216             fpCommandSetZoomHigh->GetNewDoubleValue(newValue);
00217           pViewer->fpzoom_slider->SetMaxValue (pViewer->zoom_high);
00218           pViewer->fpzoom_slider->SetInitialValue (pViewer->fVP.GetZoomFactor());
00219           if (pViewer->fVP.GetZoomFactor() > pViewer->zoom_high)
00220             {
00221               pViewer->fpzoom_slider->SetInitialValue (pViewer->zoom_high);
00222               pViewer->fVP.SetZoomFactor(pViewer->zoom_high);
00223             }
00224           else
00225             {
00226               pViewer->fpzoom_slider->SetInitialValue (pViewer->fVP.GetZoomFactor());
00227             }
00228         }
00229       else
00230         {
00231           panningControlPanel = false;
00232         }
00233     }
00234 
00235   else if (command == fpCommandSetZoomLow)
00236     {
00237       if (pViewer->fpzoom_slider)
00238         {
00239           pViewer->zoom_low =
00240             fpCommandSetZoomLow->GetNewDoubleValue(newValue);
00241           pViewer->fpzoom_slider->SetMinValue (pViewer->zoom_low);
00242           pViewer->fpzoom_slider->SetInitialValue (pViewer->fVP.GetZoomFactor());
00243           if (pViewer->fVP.GetZoomFactor() < pViewer->zoom_low)
00244             {
00245               pViewer->fpzoom_slider->SetInitialValue (pViewer->zoom_low);
00246               pViewer->fVP.SetZoomFactor(pViewer->zoom_low);
00247             }
00248           else
00249             {
00250               pViewer->fpzoom_slider->SetInitialValue (pViewer->fVP.GetZoomFactor());
00251             }
00252         }
00253       else
00254         {
00255           panningControlPanel = false;
00256         }
00257     }
00258 
00259   if (!panningControlPanel)
00260     {
00261           G4cout << 
00262             "G4OpenGLXmViewerMessenger::SetNewValue: pull down panning"
00263             "\n  control panel and re-issue command."
00264                  << G4endl;
00265           return;
00266     }
00267 
00268   if (!rotationControlPanel)
00269     {
00270           G4cout << 
00271             "G4OpenGLXmViewerMessenger::SetNewValue: pull down rotation"
00272             "\n  control panel and re-issue command."
00273                  << G4endl;
00274           return;
00275     }
00276 
00277   G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/rebuild");
00278 }
00279 
00280 #endif

Generated on Mon May 27 17:49:11 2013 for Geant4 by  doxygen 1.4.7