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.
22 #include "TKContainer.h"
31 class DCUIGraphicsScene;
33 #include "dcvcomponent.h"
38 class DCContainer : public TKContainer
43 std::string d_factoryCachedLocation;
44 DCVCRefHolder d_factoryCachedPageObject;
46 QString d_workDirRoot;
47 QString d_workDirCellRoot;
48 QString d_workDirCellCodeRoot;
52 virtual ~DCContainer();
54 virtual TKCell* addCell(std::string theLocation, std::string theName, std::string type, std::string customScript);
55 virtual TKCell* addCell(std::string theLocation, std::string theName, TKCellCode *cellCode, std::string customScript);
56 virtual TKCellCode* addCellCode(std::string theName, std::string theAPIType, std::string code);
58 virtual TKCell* cellFactory(std::string location, std::string name, std::string type, bool canInterface = true);
59 virtual TKAxon* axonFactory(TKCell *theOwner);
60 virtual TKReceptor* receptorFactory(TKCell *theOwner);
61 virtual TKAxonTerminal* axonTerminalFactory(TKAxon *theOwner);
62 virtual TKCellCode* cellCodeFactory(std::string name, std::string cellapi, std::string code);
65 * @brief remove cell from container and the page (DCVCPage) belonging.
68 * All the axon terminals connected to this cell will also be removed after this.
69 * This expected to only be called from command classes which are defined in dceditcommands.h
71 * @return true for success, false for failure
73 bool removeCell(DCCell *cell);
76 * @brief remove cell code from container and the page (DCVCPage) belonging.
79 * The cells which use the deleting cell code will have empty cell code after this.
80 * This expected to only be called from command classes which are defined in dceditcommands.h
82 * @return true for success, false for failure
84 bool removeCellCode(DCCellCode *cellcode);
89 * @param oldContainerBasedPathName
90 * @param newContainerBasedPathName
92 * Change the name / path for a container file.
93 * All cells, cell codes and connections are updated accordingly.
94 * This expected to be called from command classes which are defined in dceditcommands.h
96 * @return pointer to a page object for the new file path or NULL when this failed.
98 DCVCPage* movePage(const QString &oldContainerBasedPathName, const QString &newContainerBasedPathName);
101 * @brief change the path information of a cell.
103 * @param pageNewContainerBasedPathName
105 * @note This will be called from DCVCCell::changePageBelonging().
106 * This shouldn't be directly called from other methods.
109 bool moveCell(DCCell*cell, const QString& pageNewContainerBasedPathName);
112 * @brief change the path information of a cell code.
114 * @param pageNewContainerBasedPathName
116 * @note This will be called from DCVCCellCode::changePageBelonging().
117 * This shouldn't be directly called from other methods.
120 bool moveCellCodeClass(DCCellCode*cellcode, const QString& pageNewContainerBasedPathName);
122 bool renameCell(DCCell *cell, const QString& newName);
124 bool renameCellCodeClass(DCCellCode *cellcode, const QString& newName);
127 DCContent* getContent() const { return d_content; }
128 DCScene* getScene() const { return d_scene; }
129 QList<DCVComponent*> getSelectedCellObjects() const;
130 virtual float getValue(std::string key) const { return 0; }
132 TKCellCode* getEmptyCellCodeClass() const { return mEmptyCellClass; }
133 bool isScriptableCell(DCCell *cell);
136 void setContent(DCContent *content);
138 void unselectCellObjectAll();
140 virtual void setValue(std::string key, float value) {}
142 virtual void beganParsePage(const char *docRoot, const char *path);
143 virtual void endedParsePage(const char *docRoot, const char *path);
145 void beganBuildContainer();
146 void endedBuildContainer();
148 bool saveCustomScriptToWorkFile(TKCell *cell, std::string customScript);
149 bool saveClassScriptToWorkFile(TKCellCode *cellCode, std::string code);
151 QString sysFilePathToContainerBasedPath(const QString& sysFilePath);
152 QString containerBasedPathToSysFilePath(const QString& containerBasedPath);
154 QString readCustomScriptFromWorkFile(const DCCell *cell);
155 QString readCellCodeScriptFromFile(const DCCellCode *cellcode);
158 /***************************************************************************
160 **************************************************************************/
163 * @brief return the avaiable cell types as the list of QString
166 QList<QString> getAvailableCellTypes() const;
169 * @brief check if given cell type can have script
171 * @return true if the given cell type can have script, false if no script avaiable for the cell type.
173 bool getIsScriptable(const QString& type) const;
176 * @brief return if the cell type can accept receptors.
177 * The cell which inputs value from external can not receive value from internal cells.
181 bool getIsReceptorAvailable(const QString& type) const;
185 #endif // DCCONTAINER_H