[145498] | 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 | * ShapeRegistry.cpp
|
---|
| 25 | *
|
---|
| 26 | * Created on: Sep 13, 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 "ShapeRegistry.hpp"
|
---|
| 38 |
|
---|
| 39 | #include "CodePatterns/Singleton_impl.hpp"
|
---|
| 40 | #include "CodePatterns/Registry_impl.hpp"
|
---|
[8f6a27] | 41 | #include "CodePatterns/Observer/Channels.hpp"
|
---|
[145498] | 42 |
|
---|
[1c9588] | 43 | #include "ShapeFactory.hpp"
|
---|
| 44 |
|
---|
[8f6a27] | 45 | ShapeRegistry::ShapeRegistry() :
|
---|
| 46 | Observable::Observable("ShapeRegistry")
|
---|
[145498] | 47 | {
|
---|
[8f6a27] | 48 | Channels *OurChannel = new Channels;
|
---|
| 49 | NotificationChannels.insert( std::make_pair(this, OurChannel) );
|
---|
| 50 | // add instance for each notification type
|
---|
| 51 | for (size_t type = 0; type < NotificationType_MAX; ++type)
|
---|
| 52 | OurChannel->addChannel(type);
|
---|
[145498] | 53 | }
|
---|
| 54 |
|
---|
| 55 | ShapeRegistry::~ShapeRegistry()
|
---|
| 56 | {
|
---|
| 57 | cleanup();
|
---|
| 58 | }
|
---|
| 59 |
|
---|
[1c9588] | 60 | std::string ShapeRegistry::getDefaultNameForShape(Shape s) const
|
---|
| 61 | {
|
---|
| 62 | std::string baseName = ShapeFactory::getInstance().getShapeName(s.getType());
|
---|
| 63 | int n = 1;
|
---|
| 64 | while(true){
|
---|
| 65 | std::string name = baseName + toString(n);
|
---|
| 66 | if (!isPresentByName(name))
|
---|
| 67 | return name;
|
---|
| 68 | n ++;
|
---|
| 69 | }
|
---|
| 70 | return "";
|
---|
| 71 | }
|
---|
| 72 |
|
---|
[145498] | 73 | void ShapeRegistry::addShape(Shape s)
|
---|
| 74 | {
|
---|
[8f6a27] | 75 | OBSERVE;
|
---|
[145498] | 76 | Shape *instance = new Shape(s);
|
---|
| 77 | registerInstance(instance);
|
---|
[8f6a27] | 78 | NOTIFY(ShapeInserted);
|
---|
[145498] | 79 | }
|
---|
| 80 |
|
---|
[1c9588] | 81 | void ShapeRegistry::removeShape(const std::string &name)
|
---|
| 82 | {
|
---|
| 83 | OBSERVE;
|
---|
| 84 | Shape *instance = getByName(name);
|
---|
| 85 | unregisterInstance(instance);
|
---|
| 86 | delete(instance);
|
---|
| 87 | NOTIFY(ShapeRemoved);
|
---|
| 88 | }
|
---|
| 89 |
|
---|
[145498] | 90 | CONSTRUCT_SINGLETON(ShapeRegistry)
|
---|
| 91 | CONSTRUCT_REGISTRY(Shape)
|
---|