/
PropertyFile.h
141 lines (112 loc) · 5.3 KB
/
PropertyFile.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/***************************************************************************
* Copyright (c) 2008 Jürgen Riegel <juergen.riegel@web.de> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#ifndef APP_PROPERTFILE_H
#define APP_PROPERTFILE_H
#include <string>
#include "PropertyStandard.h"
namespace Base {
class Writer;
}
namespace App
{
/** File properties
* This property holds a file name
*/
class AppExport PropertyFile : public PropertyString
{
TYPESYSTEM_HEADER_WITH_OVERRIDE();
public:
PropertyFile();
~PropertyFile() override;
const char* getEditorName() const override
{ return "Gui::PropertyEditor::PropertyFileItem"; }
void setPyObject(PyObject *) override;
virtual void setFilter(const std::string filter);
virtual std::string getFilter() const;
private:
std::string m_filter;
};
/** File include properties
* This property doesn't only save the file name like PropertyFile
* it also includes the file itself into the document. The file
* doesn't get loaded into memory, it gets copied from the document
* archive into the document transient directory. There it is accessible for
* the algorithms. You get the transient path through getDocTransientPath()
* It's allowed to read the file, it's not allowed to write the file
* directly in the transient path! That would undermine the Undo/Redo
* framework. It's only allowed to use setValue() to change the file.
* If you give a file name outside the transient dir to setValue() it
* will copy the file. If you give a file name in the transient path it
* will just rename and use the same file. You can use getExchangeTempFile() to
* get a file name in the transient dir to write a new file version.
*/
class AppExport PropertyFileIncluded : public Property
{
TYPESYSTEM_HEADER_WITH_OVERRIDE();
public:
PropertyFileIncluded();
~PropertyFileIncluded() override;
void setValue(const char* sFile, const char* sName=nullptr);
const char* getValue() const;
const char* getEditorName() const override
{ return "Gui::PropertyEditor::PropertyTransientFileItem"; }
PyObject *getPyObject() override;
void setPyObject(PyObject *) override;
void Save (Base::Writer &writer) const override;
void Restore(Base::XMLReader &reader) override;
void SaveDocFile (Base::Writer &writer) const override;
void RestoreDocFile(Base::Reader &reader) override;
Property *Copy() const override;
void Paste(const Property &from) override;
unsigned int getMemSize () const override;
bool isSame(const Property &other) const override {
if (&other == this)
return true;
return getTypeId() == other.getTypeId()
&& _BaseFileName == static_cast<decltype(this)>(&other)->_BaseFileName
&& _OriginalName == static_cast<decltype(this)>(&other)->_OriginalName
&& _cValue == static_cast<decltype(this)>(&other)->_cValue;
}
/** get a temp file name in the transient path of the document.
* Using this file for new Version of the file and set
* this file with setValue() is the fastest way to change
* the File.
*/
std::string getExchangeTempFile() const;
std::string getOriginalFileName() const;
bool isEmpty() const {return _cValue.empty();}
void setFilter(std::string filter);
std::string getFilter() const;
protected:
// get the transient path if the property is in a DocumentObject
std::string getDocTransientPath() const;
std::string getUniqueFileName(const std::string&, const std::string&) const;
void aboutToSetValue() override;
protected:
mutable std::string _cValue;
mutable std::string _BaseFileName;
mutable std::string _OriginalName;
private:
std::string m_filter;
};
} // namespace App
#endif // APP_PROPERTFILE_H