source: trunk/source/visualization/modeling/src/G4AttFilterUtils.cc @ 1337

Last change on this file since 1337 was 1337, checked in by garnier, 14 years ago

tag geant4.9.4 beta 1 + modifs locales

File size: 3.6 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// $Id: G4AttFilterUtils.cc,v 1.4 2006/12/13 15:50:06 gunter Exp $
27// GEANT4 tag $Name: geant4-09-04-beta-01 $
28//
29// Visualisation attribute filter utility functions.
30//
31// Jane Tinslay, September 2006
32//
33#include "G4AttFilterUtils.hh"
34#include "G4AttDef.hh"
35#include "G4AttUtils.hh"
36#include "G4AttValueFilterT.hh"
37#include "G4CreatorFactoryT.hh"
38#include "G4DimensionedDouble.hh"
39#include "G4DimensionedThreeVector.hh"
40#include "G4String.hh"
41#include "G4ThreeVector.hh"
42#include "G4TypeKey.hh"
43#include "G4TypeKeyT.hh"
44#include <assert.h>
45
46namespace G4AttFilterUtils {
47 
48  namespace {
49    template <typename T>
50    G4VAttValueFilter* newFilter() {
51      return new G4AttValueFilterT<T>;
52    }
53  }
54 
55  // Create new G4AttValue filter factory
56  G4AttValueFilterFactory* GetAttValueFilterFactory() {
57    static G4AttValueFilterFactory* factory = new G4AttValueFilterFactory;
58    static G4bool init(false);
59   
60    if (!init) {
61      // Register typekey<->creator pairs
62      factory->Register(G4TypeKeyT<G4String>(), newFilter<G4String>);
63      factory->Register(G4TypeKeyT<G4int>(), newFilter<G4int>);
64      factory->Register(G4TypeKeyT<G4double>(), newFilter<G4double>);
65      factory->Register(G4TypeKeyT<G4ThreeVector>(), newFilter<G4ThreeVector>);
66      factory->Register(G4TypeKeyT<G4bool>(), newFilter<G4bool>);
67      factory->Register(G4TypeKeyT<G4DimensionedDouble>(), newFilter<G4DimensionedDouble>);
68      factory->Register(G4TypeKeyT<G4DimensionedThreeVector>(), newFilter<G4DimensionedThreeVector>);
69      init = true;
70    }
71   
72    return factory;
73  }
74 
75  G4VAttValueFilter* GetNewFilter(const G4AttDef& def) {
76   
77    G4TypeKey myKey = def.GetTypeKey();
78   
79    // Get correct type key if original G4AttDef's being used
80    if (!myKey.IsValid()) {
81      myKey = G4AttUtils::GetKey(def);
82    }
83   
84    // Should be valid now
85    assert(myKey.IsValid());
86
87    G4AttValueFilterFactory* factory = GetAttValueFilterFactory();
88 
89    G4VAttValueFilter*  filter = factory->Create(myKey);
90    assert (0 != filter);
91
92    return filter;
93  }
94 
95}
Note: See TracBrowser for help on using the repository browser.