| 1 |
/*************************************************************************** |
| 2 |
* Copyright (c) 2002 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 |
#ifndef SRC_APP_PRIVATE_DOCUMENTP_H_ |
| 24 |
#define SRC_APP_PRIVATE_DOCUMENTP_H_ |
| 25 |
|
| 26 |
#ifdef _MSC_VER |
| 27 |
#pragma warning(disable : 4834) |
| 28 |
#endif |
| 29 |
|
| 30 |
#include <map> |
| 31 |
#include <string> |
| 32 |
#include <memory> |
| 33 |
#include <vector> |
| 34 |
#include <unordered_map> |
| 35 |
#include <unordered_set> |
| 36 |
|
| 37 |
#include <boost/bimap.hpp> |
| 38 |
#include <boost/graph/adjacency_list.hpp> |
| 39 |
|
| 40 |
#include <CXX/Objects.hxx> |
| 41 |
|
| 42 |
#include <App/DocumentObject.h> |
| 43 |
#include <App/DocumentObserver.h> |
| 44 |
#include <App/StringHasher.h> |
| 45 |
#include <App/ExportInfo.h> |
| 46 |
#include <Base/UniqueNameManager.h> |
| 47 |
|
| 48 |
// using VertexProperty = boost::property<boost::vertex_root_t, DocumentObject* >; |
| 49 |
using DependencyList = boost::adjacency_list< |
| 50 |
boost::vecS, // class OutEdgeListS : a Sequence or an AssociativeContainer |
| 51 |
boost::vecS, // class VertexListS : a Sequence or a RandomAccessContainer |
| 52 |
boost::directedS, // class DirectedS : This is a directed graph |
| 53 |
boost::no_property, // class VertexProperty: |
| 54 |
boost::no_property, // class EdgeProperty: |
| 55 |
boost::no_property, // class GraphProperty: |
| 56 |
boost::listS // class EdgeListS: |
| 57 |
>; |
| 58 |
using Traits = boost::graph_traits<DependencyList>; |
| 59 |
using Vertex = Traits::vertex_descriptor; |
| 60 |
using Edge = Traits::edge_descriptor; |
| 61 |
using Node = std::vector<size_t>; |
| 62 |
using Path = std::vector<size_t>; |
| 63 |
|
| 64 |
namespace App |
| 65 |
{ |
| 66 |
using HasherMap = boost::bimap<StringHasherRef, int>; |
| 67 |
class Transaction; |
| 68 |
|
| 69 |
// Pimpl class |
| 70 |
struct DocumentP |
| 71 |
{ |
| 72 |
// Array to preserve the creation order of created objects |
| 73 |
std::vector<DocumentObject*> objectArray; |
| 74 |
std::unordered_set<App::DocumentObject*> touchedObjs; |
| 75 |
std::unordered_map<std::string, DocumentObject*> objectMap; |
| 76 |
Base::UniqueNameManager objectNameManager; |
| 77 |
Base::UniqueNameManager objectLabelManager; |
| 78 |
std::unordered_map<long, DocumentObject*> objectIdMap; |
| 79 |
std::unordered_map<std::string, bool> partialLoadObjects; |
| 80 |
std::vector<DocumentObjectT> pendingRemove; |
| 81 |
long lastObjectId {}; |
| 82 |
DocumentObject* activeObject {nullptr}; |
| 83 |
Transaction* activeUndoTransaction {nullptr}; |
| 84 |
// pointer to the python class |
| 85 |
Py::Object DocumentPythonObject; |
| 86 |
int iTransactionMode {0}; |
| 87 |
bool rollback {false}; |
| 88 |
bool undoing {false}; ///< document in the middle of undo or redo |
| 89 |
bool committing {false}; |
| 90 |
bool opentransaction {false}; |
| 91 |
std::bitset<32> StatusBits; |
| 92 |
int iUndoMode {0}; |
| 93 |
unsigned int UndoMemSize {0}; |
| 94 |
unsigned int UndoMaxStackSize {20}; |
| 95 |
std::string programVersion; |
| 96 |
mutable HasherMap hashers; |
| 97 |
std::multimap<const App::DocumentObject*, std::unique_ptr<App::DocumentObjectExecReturn>> |
| 98 |
_RecomputeLog; |
| 99 |
ExportInfo exportInfo; |
| 100 |
|
| 101 |
StringHasherRef Hasher {new StringHasher}; |
| 102 |
|
| 103 |
Document::PreRecomputeHook _preRecomputeHook; |
| 104 |
|
| 105 |
DocumentP(); |
| 106 |
|
| 107 |
void addRecomputeLog(const char* why, App::DocumentObject* obj) |
| 108 |
{ |
| 109 |
addRecomputeLog(new DocumentObjectExecReturn(why, obj)); |
| 110 |
} |
| 111 |
|
| 112 |
void addRecomputeLog(const std::string& why, App::DocumentObject* obj) |
| 113 |
{ |
| 114 |
addRecomputeLog(new DocumentObjectExecReturn(why, obj)); |
| 115 |
} |
| 116 |
|
| 117 |
void addRecomputeLog(DocumentObjectExecReturn* returnCode) |
| 118 |
{ |
| 119 |
if (!returnCode->Which) { |
| 120 |
delete returnCode; |
| 121 |
return; |
| 122 |
} |
| 123 |
_RecomputeLog.emplace(returnCode->Which, |
| 124 |
std::unique_ptr<DocumentObjectExecReturn>(returnCode)); |
| 125 |
returnCode->Which->setStatus(ObjectStatus::Error, true); |
| 126 |
} |
| 127 |
|
| 128 |
void clearRecomputeLog(const App::DocumentObject* obj = nullptr) |
| 129 |
{ |
| 130 |
if (!obj) { |
| 131 |
_RecomputeLog.clear(); |
| 132 |
} |
| 133 |
else { |
| 134 |
_RecomputeLog.erase(obj); |
| 135 |
} |
| 136 |
} |
| 137 |
|
| 138 |
void clearDocument() |
| 139 |
{ |
| 140 |
objectLabelManager.clear(); |
| 141 |
objectArray.clear(); |
| 142 |
for (auto& v : objectMap) { |
| 143 |
v.second->setStatus(ObjectStatus::Destroy, true); |
| 144 |
delete (v.second); |
| 145 |
v.second = nullptr; |
| 146 |
} |
| 147 |
objectMap.clear(); |
| 148 |
objectNameManager.clear(); |
| 149 |
objectIdMap.clear(); |
| 150 |
} |
| 151 |
|
| 152 |
const char* findRecomputeLog(const App::DocumentObject* obj) |
| 153 |
{ |
| 154 |
auto range = _RecomputeLog.equal_range(obj); |
| 155 |
if (range.first == range.second) { |
| 156 |
return nullptr; |
| 157 |
} |
| 158 |
return (--range.second)->second->Why.c_str(); |
| 159 |
} |
| 160 |
|
| 161 |
static void findAllPathsAt(const std::vector<Node>& all_nodes, |
| 162 |
size_t id, |
| 163 |
std::vector<Path>& all_paths, |
| 164 |
Path tmp); |
| 165 |
std::vector<App::DocumentObject*> |
| 166 |
topologicalSort(const std::vector<App::DocumentObject*>& objects) const; |
| 167 |
static std::vector<App::DocumentObject*> |
| 168 |
partialTopologicalSort(const std::vector<App::DocumentObject*>& objects); |
| 169 |
static void checkStringHasher(const Base::XMLReader& reader); |
| 170 |
}; |
| 171 |
|
| 172 |
} // namespace App |
| 173 |
|
| 174 |
#endif // SRC_APP_PRIVATE_DOCUMENTP_H_ |