/* * Project: MoleCuilder * Description: creates and alters molecular systems * Copyright (C) 2015 Frederik Heber. All rights reserved. * * * This file is part of MoleCuilder. * * MoleCuilder is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * MoleCuilder is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with MoleCuilder. If not, see . */ /* * MoleculeObserver.cpp * * Created on: Dec 28, 2015 * Author: heber */ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "CodePatterns/MemDebug.hpp" #include "MoleculeObserver.hpp" #include "CodePatterns/Singleton_impl.hpp" #include "molecule.hpp" /** Private constructor of class MoleculeObserver. * */ MoleculeObserver::MoleculeObserver() : Relay(std::string("MoleculeObserver")) { Channels *OurChannel = new Channels(); Observable::insertNotificationChannel( std::make_pair(static_cast(this), OurChannel) ); OurChannel->addChannel(molecule::AtomInserted); OurChannel->addChannel(molecule::AtomRemoved); OurChannel->addChannel(molecule::AtomNrChanged); OurChannel->addChannel(molecule::AtomMoved); OurChannel->addChannel(molecule::FormulaChanged); OurChannel->addChannel(molecule::MoleculeNameChanged); OurChannel->addChannel(molecule::IndexChanged); OurChannel->addChannel(molecule::BoundingBoxChanged); OurChannel->addChannel(molecule::SelectionChanged); } /** Private Destructor of class MoleculeObserver. * */ MoleculeObserver::~MoleculeObserver() {} /** Function to call when a new molecule has been created. * * @param res */ void MoleculeObserver::MoleculeInserted(molecule *res) { res->signOn(this, molecule::AtomInserted); res->signOn(this, molecule::AtomRemoved); res->signOn(this, molecule::AtomNrChanged); res->signOn(this, molecule::AtomMoved); res->signOn(this, molecule::FormulaChanged); res->signOn(this, molecule::MoleculeNameChanged); res->signOn(this, molecule::IndexChanged); res->signOn(this, molecule::BoundingBoxChanged); res->signOn(this, molecule::SelectionChanged); } /** Function to call when an molecule is about to get deleted. * * @param res */ void MoleculeObserver::MoleculeRemoved(molecule *res) { res->signOff(this, molecule::AtomInserted); res->signOff(this, molecule::AtomRemoved); res->signOff(this, molecule::AtomNrChanged); res->signOff(this, molecule::AtomMoved); res->signOff(this, molecule::FormulaChanged); res->signOff(this, molecule::MoleculeNameChanged); res->signOff(this, molecule::IndexChanged); res->signOff(this, molecule::BoundingBoxChanged); res->signOff(this, molecule::SelectionChanged); } CONSTRUCT_SINGLETON(MoleculeObserver)