Debian Codegraph @

src/App/PropertyFile.h

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