]> Creatis software - crea.git/blob - lib/creaDevManagerLib/modelCDMProject.h
Feature #1711
[crea.git] / lib / creaDevManagerLib / modelCDMProject.h
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
5 #                        pour la Sant�)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 #
10 #  This software is governed by the CeCILL-B license under French law and 
11 #  abiding by the rules of distribution of free software. You can  use, 
12 #  modify and/ or redistribute the software under the terms of the CeCILL-B 
13 #  license as circulated by CEA, CNRS and INRIA at the following URL 
14 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
15 #  or in the file LICENSE.txt.
16 #
17 #  As a counterpart to the access to the source code and  rights to copy,
18 #  modify and redistribute granted by the license, users are provided only
19 #  with a limited warranty  and the software's author,  the holder of the
20 #  economic rights,  and the successive licensors  have only  limited
21 #  liability. 
22 #
23 #  The fact that you are presently reading this means that you have had
24 #  knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ 
26  */
27
28 /*
29  * modelCDMProject.h
30  *
31  *  Created on: 13/11/2012
32  *      Author: Daniel Felipe Gonzalez Obando
33  */
34
35 #ifndef MODELCDMPROJECT_H_
36 #define MODELCDMPROJECT_H_
37
38 #include<iostream>
39 #include<vector>
40 #include <map>
41
42 #include "modelCDMFolder.h"
43 #include "modelCDMLib.h"
44 #include "modelCDMAppli.h"
45 #include "modelCDMPackage.h"
46 #include "modelCDMCMakeListsFile.h"
47
48 /**
49  * Project model class.
50  * This class represents a project stored in a hard drive. It can perform some of the most relevant operations for a crea project.
51  */
52 class modelCDMProject : public modelCDMFolder
53 {
54 public:
55   /**
56    * Default constructor.
57    */
58   modelCDMProject();
59
60   /**
61    * Constructor receiving the source path and the build path.
62    * @param path The source path.
63    * @param buildPath The build path. By default it's an empty string.
64    */
65   modelCDMProject(modelCDMIProjectTreeNode* parent, const std::string& path, const std::string& name, const std::string& buildPath = "");
66
67   /**
68    * Destructor.
69    */
70   ~modelCDMProject();
71
72
73   //Getters
74   /**
75    * Retrieves the name of the project.
76    * @return The name of the project.
77    */
78   const std::string& GetNameProject() const;
79
80   /**
81    * Retrieves the version of the project.
82    * @return The version of the project in the format X.Y.Z where X is the major version of the project, Y is the minor version of the project, and Z is the build version.
83    */
84   const std::string& GetVersion() const;
85
86   /**
87    * Retrieves the last version modification date of the project
88    * @return The date of the last version modification in the format DD/MM/YYYY
89    */
90   const std::string& GetVersionDate() const;
91
92   /**
93    * Retrieves the build path of the project.
94    * @return The build path of the project. By default .../ProjectNameBin.
95    */
96   const std::string& GetBuildPath() const;
97
98   /**
99    * Retrieves the package vector containing the packages present in the project.
100    * @return The package vector containing references to the packages of the project.
101    */
102   const std::vector<modelCDMPackage*>& GetPackages() const;
103
104   /**
105    * Retrieves the appli containing the applications present in the project.
106    * @return The appli object present in the project.
107    */
108   modelCDMAppli* GetAppli() const;
109
110   /**
111    * Retrieves the lib containing the libraries present in the project.
112    * @return The lib object present in the project.
113    */
114   modelCDMLib* GetLib() const;
115
116   /**
117    * Retrieves the default make instruction to compile the project.
118    * @return The make instruction to compile.
119    */
120   std::string GetBuildInstruction() const;
121
122
123   //Setters
124   /**
125    * Sets the version of the project. It also modifies the build date of the project.
126    * @param version New version of the project.
127    * @param result returns the result of the operation.
128    * @return If the version configuration was successful it returns true. If not, it returns false and the error description returns in the parameter result.
129    */
130   bool SetVersion(const std::string& version, std::string*& result);
131
132   /**
133    * Sets the build path of the project.
134    * @param path Path for builing the project.
135    * @param result Result of the operation.
136    * @return If the build path configuration was successful it returns true. If not, it returns false and the error description returns in the parameter result.
137    */
138   bool SetBuildPath(const std::string& path, std::string*& result);
139
140
141   //Creations
142   /**
143    * Creates a package and sets it as a children of the project. This method creates the package in the hard drive and also in the model.
144    * @param name Name of the package.
145    * @param result Result of the operation.
146    * @param authors Authors of the operation. If any space is found, it will be replaced by '_'.
147    * @param authorsEmail Authors' E-mails. This is appended to the package description.
148    * @param description Package description.
149    * @param version Package version in the format X.Y.Z where X is the major version, Y the minor version, and Z the build version.
150    * @return The result of the creation. If everything goes well it returns true, else it returns false.
151    */
152   modelCDMIProjectTreeNode* CreatePackage(
153       const std::string& name,
154       std::string*& result,
155       const std::string& authors = "info-dev",
156       const std::string& authorsEmail = "info-dev@creatis.insa-lyon.fr",
157       const std::string& description = "no description",
158       const std::string& version = "1.0.0"
159   );
160
161   /**
162    * Creates a library and sets it as a children of the lib folder in the project. This method creates the library in the hard drive and also in the model.
163    * @param name Library name.
164    * @param result Result of the operation.
165    * @param path Path of the library if not in the lib folder. This parameter is not used (for now).
166    * @return The result of the creation. If everything goes well it returns true, else it returns false.
167    */
168   modelCDMIProjectTreeNode* CreateLibrary(
169       const std::string& name,
170       std::string*& result,
171       const std::string& path = "/lib"
172   );
173
174   /**
175    * Creates an application and sets it as a children of the appli folder in the project. This method creates the library in the hard drive and also in the model.
176    * @param name Application name.
177    * @param result Result of the operation.
178    * @param path Path of the application if not in the application folder. This parameter is not used (for now).
179    * @return The result of the creation. If everything goes well it returns true, else it returns false.
180    */
181   modelCDMIProjectTreeNode* CreateApplication(
182       const std::string& name,
183       std::string*& result,
184       const std::string& path = "/appli"
185   );
186
187   /**
188    * Creates a black box and sets it as a children of the specified package folder in the project. This method creates the black box in the hard drive and also in the model.
189    * @param name Black box name.
190    * @param package The name of the package where the black box is created. The name should not contain neither the "bbtk_" , nor the "_PKG" parts of the folder name. If empty converts into "/bbtk_*projectName*_PKG"
191    * @param authors The authors of the black box. This string should not contain commas or spaces, they will be replaced by '_'.
192    * @param authorsEmail The authors e-mails. This string should not contain spaces, they will be replaced by '/'. This field is appended to the black box description.
193    * @param categories The categories of concerning for the created black box.
194    * @param description Description of the black box. It should not contain spaces, they will be replaced by '_'.
195    * @return The result of the creation. If everything goes well it returns true, else it returns false.
196    */
197   modelCDMIProjectTreeNode* CreateBlackBox(
198       const std::string& name,
199       const std::string& package = "", //if empty converts into "/bbtk_*projectName*_PKG"
200       const std::string& authors = "unknown",
201       const std::string& authorsEmail = "",
202       const std::string& categories = "empty",
203       const std::string& description = "no description"
204   );
205
206
207   //Operations
208   /**
209    * Opens the CMakeLists.txt file in the system's default text editor.
210    * @param result Result of the operation.
211    * @return Success of the operation. If the file doesn't exist or can't be opened it returns false.
212    */
213   bool OpenCMakeListsFile(std::string*& result);
214
215   /**
216    * Refresh the model with the file hierarchy in the hard drive.
217    * @param result Result of the operation.
218    * @return if there's an error refreshing the project it returns false.
219    */
220   virtual const bool Refresh(std::string*& result);
221
222   /**
223    * Launches in console the ccmake tool in the build path to configure the building of the project.
224    * @param result The result message of the operation.
225    * @return if the ccmake tool doesn't launches it returns false.
226    */
227   bool ConfigureBuild(std::string*& result);
228
229   /**
230    * Launches in console the make -clean and make commands to build the project.
231    * @param result Result message for building the project.
232    * @return if any of the commands cannot be executed it return false.
233    */
234   bool Build(std::string*& result, const std::string& line);
235
236   /**
237    * Launches in console the bbPlugPackage command to connect the project to the .bbtk folder in the hard drive.
238    * @param result Result message for connecting the project.
239    * @return if the command cannot be executed it return false.
240    */
241   bool Connect(std::string*& result);
242
243   /**
244    * Checks the CMakeLists files to see what's going to be compiled and what's not.
245    * @param properties Map containing the project compilation properties.
246    */
247   void CheckStructure(std::map<std::string, bool>& properties);
248
249
250 private:
251
252   std::string nameProject;
253   std::string version;
254   std::string versionDate;
255   std::string buildPath;
256
257   modelCDMLib* lib;
258   modelCDMAppli* appli;
259   std::vector<modelCDMPackage*> packages;
260
261 };
262
263 #endif /* MODELCDMPROJECT_H_ */