MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / SaveDocFile

Method SaveDocFile

src/Gui/Thumbnail.cpp:87–185  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

85}
86
87void Thumbnail::SaveDocFile(Base::Writer& writer) const
88{
89 QImage img;
90 bool created = false;
91
92 // 1. Try to create the thumbnail from the viewer
93 if (this->viewer) {
94 if (this->viewer->thread() != QThread::currentThread()) {
95 qWarning("Cannot create a thumbnail from non-GUI thread");
96 }
97 else {
98 QColor invalid;
99 this->viewer->imageFromFramebuffer(
100 this->size,
101 this->size,
102 4,
103 invalid,
104 img,
105 View3DInventorViewer::RenderIntent::RasterCapture
106 );
107 created = !img.isNull();
108 }
109 }
110
111 // 2. If creation failed (e.g. no viewer or background thread), try to restore from the existing file
112 if (!created) {
113 QString filename = this->uri.toLocalFile();
114 Base::FileInfo fi(filename.toUtf8().constData());
115 if (fi.exists()) {
116 try {
117 zipios::ZipFile zf(fi.filePath());
118 // getEntry uses default MatchPath=MATCH.
119 zipios::ConstEntryPointer entry = zf.getEntry("thumbnails/Thumbnail.png");
120 if (entry && entry->isValid()) {
121 // getInputStream returns a pointer that must be deleted
122 std::istream* is = zf.getInputStream(entry);
123 if (is) {
124 if (is->good()) {
125 writer.Stream() << is->rdbuf();
126 delete is;
127 return;
128 }
129 delete is;
130 }
131 }
132 }
133 catch (const std::exception&) {
134 // If the file isn't a zip or is locked, we ignore it and proceed to fallback
135 }
136 catch (...) {
137 // Ignore unknown exceptions
138 }
139 }
140 }
141
142 // If we still have no image and no viewer to generate one, we can do nothing more
143 if (!this->viewer) {
144 return;

Callers

nothing calls this directly

Calls 15

imageFromFramebufferMethod · 0.80
constDataMethod · 0.80
pixmapMethod · 0.80
GetBoolMethod · 0.80
ConfigClass · 0.50
isNullMethod · 0.45
existsMethod · 0.45
filePathMethod · 0.45
getEntryMethod · 0.45
isValidMethod · 0.45
getInputStreamMethod · 0.45

Tested by

no test coverage detected