OSDN Git Service

[denncoCreator] Implemented cell code manager dialog. The implementation is incomplet...
[dennco/denncoCreator.git] / Source / dccontainer.h
1 //  Copyright (c) 2012 Dennco Project
2 //
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.
7 //
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.
12 //
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/>.
15
16 //
17 //  Created by tkawata on Sep-30, 2012.
18 //
19 #ifndef DCCONTAINER_H
20 #define DCCONTAINER_H
21
22 #include "TKContainer.h"
23
24 class TKCell;
25 class TKCellCode;
26 class DCCell;
27 class DCCellCode;
28 class DCScene;
29 class DCContent;
30 class DCVComponent;
31 class DCUIGraphicsScene;
32
33 #include "dcvcomponent.h"
34
35 #include <QList>
36 #include <QString>
37
38 class DCContainer : public TKContainer
39 {
40     DCContent       *d_content;
41     DCScene         *d_scene;
42
43     std::string     d_factoryCachedLocation;
44     DCVCRefHolder   d_factoryCachedPageObject;
45
46     QString         d_workDirRoot;
47     QString         d_workDirCellRoot;
48     QString         d_workDirCellCodeRoot;
49
50 public:
51     DCContainer();
52     virtual ~DCContainer();
53
54     bool getIsModified() const;
55
56     virtual TKCell*         addCell(std::string theLocation, std::string theName, std::string type, std::string customScript);
57     virtual TKCell*         addCell(std::string theLocation, std::string theName, TKCellCode *cellCode, std::string customScript);
58     virtual TKCellCode*     addCellCode(std::string theName, std::string theAPIType, std::string code);
59
60     virtual TKCell*         cellFactory(std::string location, std::string name, std::string type, bool canInterface = true);
61     virtual TKAxon*         axonFactory(TKCell *theOwner);
62     virtual TKReceptor*     receptorFactory(TKCell *theOwner);
63     virtual TKAxonTerminal* axonTerminalFactory(TKAxon *theOwner);
64     virtual TKCellCode*     cellCodeFactory(std::string name, std::string cellapi, std::string code);
65
66     /**
67      * @brief remove cell from container and the page (DCVCPage) belonging.
68      * @param cell
69      *
70      * All the axon terminals connected to this cell will also be removed after this.
71      * This expected to only be called from command classes which are defined in dceditcommands.h
72      *
73      * @return true for success, false for failure
74      */
75     bool                    removeCell(DCCell *cell);
76
77     /**
78      * @brief remove cell code from container and the page (DCVCPage) belonging.
79      * @param cellcode
80      *
81      * The cells which use the deleting cell code will have empty cell code after this.
82      * This expected to only be called from command classes which are defined in dceditcommands.h
83      *
84      * @return true for success, false for failure
85      */
86     bool                    removeCellCode(DCCellCode *cellcode);
87
88     /**
89      * @brief movePage
90      *
91      * @param oldContainerBasedPathName
92      * @param newContainerBasedPathName
93      *
94      * Change the name / path for a container file.
95      * All cells, cell codes and connections are updated accordingly.
96      * This expected to be called from command classes which are defined in dceditcommands.h
97      *
98      * @return pointer to a page object for the new file path or NULL when this failed.
99      */
100     DCVCPage*               movePage(const QString &oldContainerBasedPathName, const QString &newContainerBasedPathName);
101
102     /**
103      * @brief change the path information of a cell.
104      * @param cell
105      * @param pageNewContainerBasedPathName
106      *
107      * @note This will be called from DCVCCell::changePageBelonging().
108      * This shouldn't be directly called from other methods.
109      * @return
110      */
111     bool                    moveCell(DCCell*cell, const QString& pageNewContainerBasedPathName);
112
113     /**
114      * @brief change the path information of a cell code.
115      * @param cellcode
116      * @param pageNewContainerBasedPathName
117      *
118      * @note This will be called from DCVCCellCode::changePageBelonging().
119      * This shouldn't be directly called from other methods.
120      * @return
121      */
122     bool                    moveCellCodeClass(DCCellCode*cellcode, const QString& pageNewContainerBasedPathName);
123
124     bool                    renameCell(DCCell *cell, const QString& newName);
125
126     bool                    renameCellCodeClass(DCCellCode *cellcode, const QString& newName);
127
128     //
129     DCContent*              getContent() const { return d_content; }
130     DCScene*                getScene() const { return d_scene; }
131     QList<DCVComponent*>    getSelectedCellObjects() const;
132     virtual float           getValue(std::string key) const { Q_UNUSED(key); return 0; }
133
134     TKCellCode*             getEmptyCellCodeClass() const { return mEmptyCellClass; }
135     bool                    isScriptableCell(DCCell *cell);
136
137     //
138     void                    setContent(DCContent *content);
139
140     void                    unselectCellObjectAll();
141
142     virtual void            setValue(std::string key, float value) { Q_UNUSED(key); Q_UNUSED(value);}
143
144     virtual void            beganParsePage(const char *docRoot, const char *path);
145     virtual void            endedParsePage(const char *docRoot, const char *path);
146
147     void                    beganBuildContainer();
148     void                    endedBuildContainer();
149
150     bool                    saveCustomScriptToWorkFile(DCCell *cell, std::string customScript);
151     bool                    saveClassScriptToWorkFile(DCCellCode *cellCode, std::string code);
152
153     QString                 sysFilePathToContainerBasedPath(const QString& sysFilePath);
154     QString                 containerBasedPathToSysFilePath(const QString& containerBasedPath);
155
156     QString                 readCustomScriptFromWorkFile(const DCCell *cell);
157     QString                 readCellCodeScriptFromFile(const DCCellCode *cellcode);
158
159
160     /***************************************************************************
161      * Cell type rules
162      **************************************************************************/
163
164     /**
165      * @brief return the avaiable cell types as the list of QString
166      * @return
167      */
168     QList<QString>          getAvailableCellTypes() const;
169
170     QList<QString>          getAvailableScriptableCellTypes() const;
171
172     /**
173      * @brief check if given cell type can have script
174      * @param type
175      * @return true if the given cell type can have script, false if no script avaiable for the cell type.
176      */
177     bool                    getIsScriptable(const QString& type) const;
178
179     /**
180      * @brief return if the cell type can accept receptors.
181      *        The cell which inputs value from external can not receive value from internal cells.
182      * @param type
183      * @return
184      */
185     bool                    getIsReceptorAvailable(const QString& type) const;
186
187 };
188
189 #endif // DCCONTAINER_H