1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
---|
5 | *
|
---|
6 | *
|
---|
7 | * This file is part of MoleCuilder.
|
---|
8 | *
|
---|
9 | * MoleCuilder is free software: you can redistribute it and/or modify
|
---|
10 | * it under the terms of the GNU General Public License as published by
|
---|
11 | * the Free Software Foundation, either version 2 of the License, or
|
---|
12 | * (at your option) any later version.
|
---|
13 | *
|
---|
14 | * MoleCuilder is distributed in the hope that it will be useful,
|
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
17 | * GNU General Public License for more details.
|
---|
18 | *
|
---|
19 | * You should have received a copy of the GNU General Public License
|
---|
20 | * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
|
---|
21 | */
|
---|
22 |
|
---|
23 | /*
|
---|
24 | * ShapeFactory.cpp
|
---|
25 | *
|
---|
26 | * Created on: Sep 5, 2012
|
---|
27 | * Author: ankele
|
---|
28 | */
|
---|
29 |
|
---|
30 | // include config.h
|
---|
31 | #ifdef HAVE_CONFIG_H
|
---|
32 | #include <config.h>
|
---|
33 | #endif
|
---|
34 |
|
---|
35 | #include "CodePatterns/MemDebug.hpp"
|
---|
36 |
|
---|
37 | #include "ShapeFactory.hpp"
|
---|
38 |
|
---|
39 | #include "CodePatterns/Singleton_impl.hpp"
|
---|
40 |
|
---|
41 | const char *ShapeFactory::shapeNames[ShapeFactory::SHAPETYPES_MAX] = {"sphere", "cube", "cylinder"};
|
---|
42 |
|
---|
43 | ShapeFactory::ShapeFactory()
|
---|
44 | {
|
---|
45 | // Create map (type -> name).
|
---|
46 | for (int i=0; i<SHAPETYPES_MAX; i++)
|
---|
47 | shapeNameMap.insert(std::pair<ShapeType, std::string>((ShapeType)i, shapeNames[i]));
|
---|
48 |
|
---|
49 | // Create inverse map.
|
---|
50 | for (int i=0; i<SHAPETYPES_MAX; i++)
|
---|
51 | nameShapeMap.insert(std::pair<std::string, ShapeType>(shapeNames[i], (ShapeType)i));
|
---|
52 |
|
---|
53 | // Init state.
|
---|
54 | type = SPHERE;
|
---|
55 | translation.Zero();
|
---|
56 | stretch.Zero();
|
---|
57 | for (int i=0; i<NDIM; i++)
|
---|
58 | angle[i] = 0;
|
---|
59 | }
|
---|
60 |
|
---|
61 | ShapeFactory::ShapeType ShapeFactory::getShapeByName(const std::string& name)
|
---|
62 | {
|
---|
63 | NameShapeMap::iterator iter = nameShapeMap.find(name);
|
---|
64 | ASSERT(iter != nameShapeMap.end(),
|
---|
65 | "ShapeFactory::getShapeByName() - unknown name: "+name+".");
|
---|
66 | return iter->second;
|
---|
67 | }
|
---|
68 |
|
---|
69 | std::string ShapeFactory::getShapeName(ShapeType type)
|
---|
70 | {
|
---|
71 | ShapeNameMap::iterator iter = shapeNameMap.find(type);
|
---|
72 | ASSERT(iter != shapeNameMap.end(),
|
---|
73 | "ShapeFactory::getShapeName() - unknown type: "+toString(type)+".");
|
---|
74 | return iter->second;
|
---|
75 | }
|
---|
76 |
|
---|
77 | ShapeFactory::~ShapeFactory()
|
---|
78 | {
|
---|
79 | }
|
---|
80 |
|
---|
81 |
|
---|
82 | void ShapeFactory::setStretch(const Vector &stretch)
|
---|
83 | {
|
---|
84 | ASSERT(!stretch.IsZero(),
|
---|
85 | "ShapeFactory::setStretch() - stretch is zero.");
|
---|
86 | this->stretch = stretch;
|
---|
87 | }
|
---|
88 |
|
---|
89 | CONSTRUCT_SINGLETON(ShapeFactory)
|
---|