doxygen: prevent GPL license block from being parsed as doxygen comment.
[blender.git] / source / blender / collada / ImageExporter.cpp
1 /*
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * Contributor(s): Chingiz Dyussenov, Arystanbek Dyussenov, Jan Diederich, Tod Liverseed,
21  *                 Nathan Letwory
22  *
23  * ***** END GPL LICENSE BLOCK *****
24  */
25
26 #include "COLLADABUURI.h"
27 #include "COLLADASWImage.h"
28
29 #include "ImageExporter.h"
30 #include "MaterialExporter.h"
31
32 #include "DNA_texture_types.h"
33
34 #include "BKE_global.h"
35 #include "BKE_main.h"
36 #include "BKE_utildefines.h"
37 #include "BLI_fileops.h"
38 #include "BLI_path_util.h"
39 #include "BLI_string.h"
40
41 ImagesExporter::ImagesExporter(COLLADASW::StreamWriter *sw, const char* filename) : COLLADASW::LibraryImages(sw), mfilename(filename)
42 {}
43
44 void ImagesExporter::exportImages(Scene *sce)
45 {
46         openLibrary();
47         MaterialFunctor mf;
48         mf.forEachMaterialInScene<ImagesExporter>(sce, *this);
49
50         closeLibrary();
51 }
52
53 void ImagesExporter::operator()(Material *ma, Object *ob)
54 {
55         int a;
56         for (a = 0; a < MAX_MTEX; a++) {
57                 MTex *mtex = ma->mtex[a];
58                 if (mtex && mtex->tex && mtex->tex->ima) {
59
60                         Image *image = mtex->tex->ima;
61                         std::string name(id_name(image));
62                         name = translate_id(name);
63                         char rel[FILE_MAX];
64                         char abs[FILE_MAX];
65                         char src[FILE_MAX];
66                         char dir[FILE_MAX];
67                         
68                         BLI_split_dirfile(mfilename, dir, NULL);
69
70                         BKE_rebase_path(abs, sizeof(abs), rel, sizeof(rel), G.main->name, image->name, dir);
71
72                         if (abs[0] != '\0') {
73
74                                 // make absolute source path
75                                 BLI_strncpy(src, image->name, sizeof(src));
76                                 BLI_path_abs(src, G.main->name);
77
78                                 // make dest directory if it doesn't exist
79                                 BLI_make_existing_file(abs);
80                         
81                                 if (BLI_copy_fileops(src, abs) != 0) {
82                                         fprintf(stderr, "Cannot copy image to file's directory. \n");
83                                 }
84                         } 
85                         
86                         if (find(mImages.begin(), mImages.end(), name) == mImages.end()) {
87                                 COLLADASW::Image img(COLLADABU::URI(COLLADABU::URI::nativePathToUri(rel)), name, name); /* set name also to mNameNC. This helps other viewers import files exported from Blender better */
88                                 img.add(mSW);
89
90                                 mImages.push_back(name);
91                         }
92                 }
93         }
94 }