1 // Copyright (c) 2012 Dennco Project
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 // Created by tkawata on Sep-30, 2012.
19 #include "dccomponentutil.h"
23 #include "dccellcode.h"
24 #include "dcvccellcode.h"
27 #include "dcaxonterminal.h"
28 #include "dcvcaxonterminal.h"
29 #include "dcreceptor.h"
30 #include "dcvcreceptor.h"
32 #include "TKReceptor.h"
33 #include "dcvceditmodeterminal.h"
38 DCCell* DCComponentUtil::createCell(DCContainer *container, DCVCPage *page, std::string location, std::string name, std::string type, bool canInterface)
40 DCCell *cell = new DCCell(container, location, name, type, canInterface);
41 DCVPageComponent *vcompo = new DCVCCell(cell, page, 0.5, 0.5);
42 cell->bindComponent(vcompo);
43 page->registerCell(vcompo);
49 DCCellCode* DCComponentUtil::createCellCode(DCContainer *container, DCVCPage *page, std::string theName, std::string theCellAPIName)
51 DCCellCode *cellcode = new DCCellCode(container, theName, theCellAPIName);
52 DCVPageComponent *vcompo = new DCVCCellCode(cellcode, page);
53 cellcode->bindComponent(vcompo);
55 page->registerCellCodeClass(vcompo);
61 DCAxon* DCComponentUtil::createAxon(DCCell *theOwner)
63 DCAxon *axon = new DCAxon(theOwner);
64 axon->bindComponent(new DCVCAxon(axon));
70 DCAxonTerminal* DCComponentUtil::createAxonTerminal(DCAxon *theOwner)
72 DCAxonTerminal *axonTerminal = new DCAxonTerminal(theOwner);
73 axonTerminal->bindComponent(new DCVCAxonTerminal(axonTerminal));
79 DCReceptor* DCComponentUtil::createReceptor(DCCell *theOwner)
81 DCReceptor *receptor = new DCReceptor(theOwner);
82 receptor->bindComponent(new DCVCReceptor(receptor));
88 bool DCComponentUtil::isConnectedToSelectedCell(DCVComponent *vcell)
90 DCCell *cell = dynamic_cast<DCVCCell*>(vcell)->getOwnerCell();
92 const TKReceptorMap *receptors = cell->getReceptors();
93 for ( TKReceptorMap::const_iterator it = receptors->begin(); it != receptors->end(); ++it )
95 DCReceptor *receptor = dynamic_cast<DCReceptor*>(it->second);
96 if ( receptor && receptor->getTarget() && ((DCCell*)receptor->getTarget()->getOwner()->getOwner())->getVComponent()->getIsSelected())
105 DCAxon *axon = cell->getAxon();
108 for (int i = axon->getNumberOfTerminals()-1; i >= 0; i--)
110 DCAxonTerminal *terminal = axon->getTerminalAt(i);
111 if (terminal && terminal->getTarget() && ((DCCell*)terminal->getTarget()->getOwnerCell())->getVComponent()->getIsSelected())