OSDN Git Service

[denncoCreator] small refactoring to remove a redundant code.
[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     DCContent*              getContent() const { return d_content; }
57     DCScene*                getScene() const { return d_scene; }
58     QList<DCVComponent*>    getSelectedCellObjects() const;
59     virtual float           getValue(std::string key) const { Q_UNUSED(key); return 0; }
60
61     TKCellCode*             getEmptyCellCodeClass() const { return mEmptyCellClass; }
62     bool                    getIsScriptableCell(const DCCell *cell) const;
63
64     QString                 getWorkFilePathForCustomScript(const DCCell *cell) const;
65     QString                 getWorkFilePathForCellCode(const DCCellCode *cellcode) const;
66
67     virtual TKCell*         addCell(std::string theLocation, std::string theName, std::string type, std::string customScript);
68     virtual TKCell*         addCell(std::string theLocation, std::string theName, TKCellCode *cellCode, std::string customScript);
69     virtual TKCellCode*     addCellCode(std::string theName, std::string theAPIType, std::string code);
70
71     virtual TKCell*         cellFactory(std::string location, std::string name, std::string type, bool canInterfaceIn, bool canInterfaceOut);
72     virtual TKCell*         pluginCellFactory(std::string location, std::string fullName, std::string type, std::string pluginName, std::string pluginValue, bool canInterfaceIn, bool canInterfaceOut);
73     virtual TKAxon*         axonFactory(TKCell *theOwner);
74     virtual TKReceptor*     receptorFactory(TKCell *theOwner);
75     virtual TKAxonTerminal* axonTerminalFactory(TKAxon *theOwner);
76     virtual TKCellCode*     cellCodeFactory(std::string name, std::string cellapi, std::string code);
77
78     /**
79      * @brief remove cell from container and the page (DCVCPage) belonging.
80      * @param cell
81      *
82      * All the axon terminals connected to this cell will also be removed after this.
83      * This expected to only be called from command classes which are defined in dceditcommands.h
84      *
85      * @return true for success, false for failure
86      */
87     bool                    removeCell(DCCell *cell);
88
89     /**
90      * @brief remove cell code from container and the page (DCVCPage) belonging.
91      * @param cellcode
92      *
93      * The cells which use the deleting cell code will have empty cell code after this.
94      * This expected to only be called from command classes which are defined in dceditcommands.h
95      *
96      * @return true for success, false for failure
97      */
98     bool                    removeCellCode(DCCellCode *cellcode);
99
100     /**
101      * @brief movePage
102      *
103      * @param oldContainerBasedPathName
104      * @param newContainerBasedPathName
105      *
106      * Change the name / path for a container file.
107      * All cells, cell codes and connections are updated accordingly.
108      * This expected to be called from command classes which are defined in dceditcommands.h
109      *
110      * @return pointer to a page object for the new file path or NULL when this failed.
111      */
112     DCVCPage*               movePage(const QString &oldContainerBasedPathName, const QString &newContainerBasedPathName);
113
114     /**
115      * @brief change the path information of a cell.
116      * @param cell
117      * @param pageNewContainerBasedPathName
118      *
119      * @note This will be called from DCVCCell::changePageBelonging().
120      * This shouldn't be directly called from other methods.
121      * @return
122      */
123     bool                    moveCell(DCCell*cell, const QString& pageNewContainerBasedPathName);
124
125     /**
126      * @brief change the path information of a cell code.
127      * @param cellcode
128      * @param pageNewContainerBasedPathName
129      *
130      * @note This will be called from DCVCCellCode::changePageBelonging().
131      * This shouldn't be directly called from other methods.
132      * @return
133      */
134     bool                    moveCellCodeClass(DCCellCode*cellcode, const QString& pageNewContainerBasedPathName);
135
136     bool                    renameCell(DCCell *cell, const QString& newName);
137
138     bool                    renameCellCodeClass(DCCellCode *cellcode, const QString& newName);
139
140     void                    setContent(DCContent *content);
141
142     void                    unselectCellObjectAll();
143
144     virtual void            setValue(std::string key, float value) { Q_UNUSED(key); Q_UNUSED(value);}
145
146     virtual void            beganParsePage(const char *docRoot, const char *path);
147     virtual void            endedParsePage(const char *docRoot, const char *path);
148
149     void                    beganBuildContainer();
150     void                    endedBuildContainer();
151
152     bool                    saveCustomScriptToWorkFile(const DCCell *cell, std::string customScript);
153     bool                    saveClassScriptToWorkFile(const DCCellCode *cellCode, std::string code);
154
155     QString                 sysFilePathToContainerBasedPath(const QString& sysFilePath);
156     QString                 containerBasedPathToSysFilePath(const QString& containerBasedPath);
157
158     QString                 readCustomScriptFromWorkFile(const DCCell *cell);
159     QString                 readCellCodeScriptFromFile(const DCCellCode *cellcode);
160
161     /***************************************************************************
162      * Cell type rules
163      **************************************************************************/
164
165     /**
166      * @brief return the avaiable cell types as the list of QString
167      * @return
168      */
169     QList<QString>          getAvailableCellTypes() const;
170
171     QList<QString>          getAvailableScriptableCellTypes() const;
172
173     /**
174      * @brief check if given cell type can have script
175      * @param type
176      * @return true if the given cell type can have script, false if no script avaiable for the cell type.
177      */
178     bool                    getIsScriptable(const QString& type) const;
179
180     /**
181      * @brief return if the cell type can accept receptors.
182      *        The cell which inputs value from external can not receive value from internal cells.
183      * @param type
184      * @return
185      */
186     bool                    getIsReceptorAvailable(const QString& type) const;
187
188     /***************************************************************************
189      * plugin rules
190      **************************************************************************/
191
192     bool                    getIsPluginType(const QString& type) const;
193     QList<QString>          getAvailablePluginLibraries() const;
194     QString                 createPluginCellName(const QString& name, const QString& type, const QString& libraryName);
195 };
196
197 #endif // DCCONTAINER_H