| 1 |
/**************************************************************************** |
| 2 |
* Copyright (c) 2017 Zheng Lei (realthunder) <[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 APP_LINK_H |
| 24 |
#define APP_LINK_H |
| 25 |
|
| 26 |
#include <unordered_set> |
| 27 |
#include <Base/Parameter.h> |
| 28 |
#include <Base/Bitmask.h> |
| 29 |
#include "DocumentObject.h" |
| 30 |
#include "DocumentObjectExtension.h" |
| 31 |
#include "FeaturePython.h" |
| 32 |
#include "GroupExtension.h" |
| 33 |
#include "PropertyLinks.h" |
| 34 |
|
| 35 |
|
| 36 |
// FIXME: ISO C++11 requires at least one argument for the "..." in a variadic macro |
| 37 |
#if defined(__clang__) |
| 38 |
#pragma clang diagnostic push |
| 39 |
#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" |
| 40 |
#endif |
| 41 |
|
| 42 |
#define LINK_THROW(_type, _msg) \ |
| 43 |
do { \ |
| 44 |
if (FC_LOG_INSTANCE.isEnabled(FC_LOGLEVEL_LOG)) \ |
| 45 |
FC_ERR(_msg); \ |
| 46 |
throw _type(_msg); \ |
| 47 |
} while (0) |
| 48 |
|
| 49 |
namespace App |
| 50 |
{ |
| 51 |
|
| 52 |
class AppExport LinkBaseExtension: public App::DocumentObjectExtension |
| 53 |
{ |
| 54 |
EXTENSION_PROPERTY_HEADER_WITH_OVERRIDE(App::LinkExtension); |
| 55 |
using inherited = App::DocumentObjectExtension; |
| 56 |
|
| 57 |
public: |
| 58 |
LinkBaseExtension(); |
| 59 |
~LinkBaseExtension() override = default; |
| 60 |
|
| 61 |
PropertyBool _LinkTouched; |
| 62 |
PropertyInteger _LinkOwner; |
| 63 |
PropertyLinkList _ChildCache; // cache for plain group expansion |
| 64 |
|
| 65 |
enum |
| 66 |
{ |
| 67 |
LinkModeNone, |
| 68 |
LinkModeAutoDelete, |
| 69 |
LinkModeAutoLink, |
| 70 |
LinkModeAutoUnlink, |
| 71 |
}; |
| 72 |
|
| 73 |
/** \name Parameter definition |
| 74 |
* |
| 75 |
* Parameter definition (Name, Type, Property Type, Default, Document). |
| 76 |
* The variadic is here so that the parameter can be extended by adding |
| 77 |
* extra fields. See LINK_PARAM_EXT() for an example |
| 78 |
*/ |
| 79 |
//@{ |
| 80 |
|
| 81 |
#define LINK_PARAM_LINK_PLACEMENT(...) \ |
| 82 |
(LinkPlacement, \ |
| 83 |
Base::Placement, \ |
| 84 |
App::PropertyPlacement, \ |
| 85 |
Base::Placement(), \ |
| 86 |
"Link placement", \ |
| 87 |
##__VA_ARGS__) |
| 88 |
|
| 89 |
#define LINK_PARAM_PLACEMENT(...) \ |
| 90 |
(Placement, \ |
| 91 |
Base::Placement, \ |
| 92 |
App::PropertyPlacement, \ |
| 93 |
Base::Placement(), \ |
| 94 |
"Alias to LinkPlacement to make the link object compatibale with other objects", \ |
| 95 |
##__VA_ARGS__) |
| 96 |
|
| 97 |
#define LINK_PARAM_OBJECT(...) \ |
| 98 |
(LinkedObject, App::DocumentObject*, App::PropertyLink, 0, "Linked object", ##__VA_ARGS__) |
| 99 |
|
| 100 |
#define LINK_PARAM_TRANSFORM(...) \ |
| 101 |
(LinkTransform, \ |
| 102 |
bool, \ |
| 103 |
App::PropertyBool, \ |
| 104 |
false, \ |
| 105 |
"Set to false to override linked object's placement", \ |
| 106 |
##__VA_ARGS__) |
| 107 |
|
| 108 |
#define LINK_PARAM_CLAIM_CHILD(...) \ |
| 109 |
(LinkClaimChild, \ |
| 110 |
bool, \ |
| 111 |
App::PropertyBool, \ |
| 112 |
false, \ |
| 113 |
"Claim the linked object as a child", \ |
| 114 |
##__VA_ARGS__) |
| 115 |
|
| 116 |
#define LINK_PARAM_COPY_ON_CHANGE(...) \ |
| 117 |
(LinkCopyOnChange, \ |
| 118 |
long, \ |
| 119 |
App::PropertyEnumeration, \ |
| 120 |
((long)0), \ |
| 121 |
"Disabled: disable copy on change\n" \ |
| 122 |
"Enabled: enable copy linked object on change of any of its properties marked as " \ |
| 123 |
"CopyOnChange\n" \ |
| 124 |
"Owned: indicate the linked object has been copied and is own owned by the link. And the\n" \ |
| 125 |
" the link will try to sync any change of the original linked object back to the " \ |
| 126 |
"copy.", \ |
| 127 |
##__VA_ARGS__) |
| 128 |
|
| 129 |
#define LINK_PARAM_COPY_ON_CHANGE_SOURCE(...) \ |
| 130 |
(LinkCopyOnChangeSource, \ |
| 131 |
App::DocumentObject*, \ |
| 132 |
App::PropertyLink, \ |
| 133 |
0, \ |
| 134 |
"The copy on change source object", \ |
| 135 |
##__VA_ARGS__) |
| 136 |
|
| 137 |
#define LINK_PARAM_COPY_ON_CHANGE_GROUP(...) \ |
| 138 |
(LinkCopyOnChangeGroup, \ |
| 139 |
App::DocumentObject*, \ |
| 140 |
App::PropertyLink, \ |
| 141 |
0, \ |
| 142 |
"Linked to a internal group object for holding on change copies", \ |
| 143 |
##__VA_ARGS__) |
| 144 |
|
| 145 |
#define LINK_PARAM_COPY_ON_CHANGE_TOUCHED(...) \ |
| 146 |
(LinkCopyOnChangeTouched, \ |
| 147 |
bool, \ |
| 148 |
App::PropertyBool, \ |
| 149 |
0, \ |
| 150 |
"Indicating the copy on change source object has been changed", \ |
| 151 |
##__VA_ARGS__) |
| 152 |
|
| 153 |
#define LINK_PARAM_SCALE(...) \ |
| 154 |
(Scale, double, App::PropertyFloat, 1.0, "Scale factor", ##__VA_ARGS__) |
| 155 |
|
| 156 |
#define LINK_PARAM_SCALE_VECTOR(...) \ |
| 157 |
(ScaleVector, \ |
| 158 |
Base::Vector3d, \ |
| 159 |
App::PropertyVector, \ |
| 160 |
Base::Vector3d(1, 1, 1), \ |
| 161 |
"Scale factors", \ |
| 162 |
##__VA_ARGS__) |
| 163 |
|
| 164 |
#define LINK_PARAM_PLACEMENTS(...) \ |
| 165 |
(PlacementList, \ |
| 166 |
std::vector<Base::Placement>, \ |
| 167 |
App::PropertyPlacementList, \ |
| 168 |
std::vector<Base::Placement>(), \ |
| 169 |
"The placement for each link element", \ |
| 170 |
##__VA_ARGS__) |
| 171 |
|
| 172 |
#define LINK_PARAM_SCALES(...) \ |
| 173 |
(ScaleList, \ |
| 174 |
std::vector<Base::Vector3d>, \ |
| 175 |
App::PropertyVectorList, \ |
| 176 |
std::vector<Base::Vector3d>(), \ |
| 177 |
"The scale factors for each link element", \ |
| 178 |
##__VA_ARGS__) |
| 179 |
|
| 180 |
#define LINK_PARAM_VISIBILITIES(...) \ |
| 181 |
(VisibilityList, \ |
| 182 |
boost::dynamic_bitset<>, \ |
| 183 |
App::PropertyBoolList, \ |
| 184 |
boost::dynamic_bitset<>(), \ |
| 185 |
"The visibility state of each link element", \ |
| 186 |
##__VA_ARGS__) |
| 187 |
|
| 188 |
#define LINK_PARAM_COUNT(...) \ |
| 189 |
(ElementCount, int, App::PropertyInteger, 0, "Link element count", ##__VA_ARGS__) |
| 190 |
|
| 191 |
#define LINK_PARAM_ELEMENTS(...) \ |
| 192 |
(ElementList, \ |
| 193 |
std::vector<App::DocumentObject*>, \ |
| 194 |
App::PropertyLinkList, \ |
| 195 |
std::vector<App::DocumentObject*>(), \ |
| 196 |
"The link element object list", \ |
| 197 |
##__VA_ARGS__) |
| 198 |
|
| 199 |
#define LINK_PARAM_SHOW_ELEMENT(...) \ |
| 200 |
(ShowElement, bool, App::PropertyBool, true, "Enable link element list", ##__VA_ARGS__) |
| 201 |
|
| 202 |
#define LINK_PARAM_MODE(...) \ |
| 203 |
(LinkMode, long, App::PropertyEnumeration, ((long)0), "Link group mode", ##__VA_ARGS__) |
| 204 |
|
| 205 |
#define LINK_PARAM_LINK_EXECUTE(...) \ |
| 206 |
(LinkExecute, \ |
| 207 |
const char*, \ |
| 208 |
App::PropertyString, \ |
| 209 |
(""), \ |
| 210 |
"Link execute function. Default to 'appLinkExecute'. 'None' to disable.", \ |
| 211 |
##__VA_ARGS__) |
| 212 |
|
| 213 |
#define LINK_PARAM_COLORED_ELEMENTS(...) \ |
| 214 |
(ColoredElements, \ |
| 215 |
App::DocumentObject*, \ |
| 216 |
App::PropertyLinkSubHidden, \ |
| 217 |
0, \ |
| 218 |
"Link colored elements", \ |
| 219 |
##__VA_ARGS__) |
| 220 |
|
| 221 |
#define LINK_PARAM(_param) (LINK_PARAM_##_param()) |
| 222 |
|
| 223 |
#define LINK_PNAME(_param) BOOST_PP_TUPLE_ELEM(0, _param) |
| 224 |
#define LINK_PTYPE(_param) BOOST_PP_TUPLE_ELEM(1, _param) |
| 225 |
#define LINK_PPTYPE(_param) BOOST_PP_TUPLE_ELEM(2, _param) |
| 226 |
#define LINK_PDEF(_param) BOOST_PP_TUPLE_ELEM(3, _param) |
| 227 |
#define LINK_PDOC(_param) BOOST_PP_TUPLE_ELEM(4, _param) |
| 228 |
|
| 229 |
#define LINK_PINDEX(_param) BOOST_PP_CAT(Prop, LINK_PNAME(_param)) |
| 230 |
//@} |
| 231 |
|
| 232 |
#define LINK_PARAMS \ |
| 233 |
LINK_PARAM(PLACEMENT) \ |
| 234 |
LINK_PARAM(LINK_PLACEMENT) \ |
| 235 |
LINK_PARAM(OBJECT) \ |
| 236 |
LINK_PARAM(CLAIM_CHILD) \ |
| 237 |
LINK_PARAM(TRANSFORM) \ |
| 238 |
LINK_PARAM(SCALE) \ |
| 239 |
LINK_PARAM(SCALE_VECTOR) \ |
| 240 |
LINK_PARAM(PLACEMENTS) \ |
| 241 |
LINK_PARAM(SCALES) \ |
| 242 |
LINK_PARAM(VISIBILITIES) \ |
| 243 |
LINK_PARAM(COUNT) \ |
| 244 |
LINK_PARAM(ELEMENTS) \ |
| 245 |
LINK_PARAM(SHOW_ELEMENT) \ |
| 246 |
LINK_PARAM(MODE) \ |
| 247 |
LINK_PARAM(LINK_EXECUTE) \ |
| 248 |
LINK_PARAM(COLORED_ELEMENTS) \ |
| 249 |
LINK_PARAM(COPY_ON_CHANGE) \ |
| 250 |
LINK_PARAM(COPY_ON_CHANGE_SOURCE) \ |
| 251 |
LINK_PARAM(COPY_ON_CHANGE_GROUP) \ |
| 252 |
LINK_PARAM(COPY_ON_CHANGE_TOUCHED) |
| 253 |
|
| 254 |
enum PropIndex |
| 255 |
{ |
| 256 |
#define LINK_PINDEX_DEFINE(_1, _2, _param) LINK_PINDEX(_param), |
| 257 |
|
| 258 |
// defines Prop##Name enumeration value |
| 259 |
BOOST_PP_SEQ_FOR_EACH(LINK_PINDEX_DEFINE, _, LINK_PARAMS) PropMax |
| 260 |
}; |
| 261 |
|
| 262 |
virtual void setProperty(int idx, Property* prop); |
| 263 |
Property* getProperty(int idx); |
| 264 |
Property* getProperty(const char*); |
| 265 |
|
| 266 |
struct PropInfo |
| 267 |
{ |
| 268 |
int index; |
| 269 |
const char* name; |
| 270 |
Base::Type type; |
| 271 |
const char* doc; |
| 272 |
|
| 273 |
PropInfo(int index, const char* name, Base::Type type, const char* doc) |
| 274 |
: index(index) |
| 275 |
, name(name) |
| 276 |
, type(type) |
| 277 |
, doc(doc) |
| 278 |
{} |
| 279 |
|
| 280 |
PropInfo() |
| 281 |
: index(0) |
| 282 |
, name(nullptr) |
| 283 |
, doc(nullptr) |
| 284 |
{} |
| 285 |
}; |
| 286 |
|
| 287 |
#define LINK_PROP_INFO(_1, _var, _param) \ |
| 288 |
_var.push_back(PropInfo(BOOST_PP_CAT(Prop, LINK_PNAME(_param)), \ |
| 289 |
BOOST_PP_STRINGIZE(LINK_PNAME(_param)), \ |
| 290 |
LINK_PPTYPE(_param)::getClassTypeId(), \ |
| 291 |
LINK_PDOC(_param))); |
| 292 |
|
| 293 |
virtual const std::vector<PropInfo>& getPropertyInfo() const; |
| 294 |
|
| 295 |
using PropInfoMap = std::map<std::string, PropInfo>; |
| 296 |
virtual const PropInfoMap& getPropertyInfoMap() const; |
| 297 |
|
| 298 |
enum LinkCopyOnChangeType |
| 299 |
{ |
| 300 |
CopyOnChangeDisabled = 0, |
| 301 |
CopyOnChangeEnabled = 1, |
| 302 |
CopyOnChangeOwned = 2, |
| 303 |
CopyOnChangeTracking = 3 |
| 304 |
}; |
| 305 |
|
| 306 |
#define LINK_PROP_GET(_1, _2, _param) \ |
| 307 |
LINK_PTYPE(_param) BOOST_PP_SEQ_CAT((get)(LINK_PNAME(_param))(Value))() const \ |
| 308 |
{ \ |
| 309 |
auto prop = props[LINK_PINDEX(_param)]; \ |
| 310 |
if (!prop) \ |
| 311 |
return LINK_PDEF(_param); \ |
| 312 |
return static_cast<const LINK_PPTYPE(_param)*>(prop)->getValue(); \ |
| 313 |
} \ |
| 314 |
const LINK_PPTYPE(_param) * BOOST_PP_SEQ_CAT((get)(LINK_PNAME(_param))(Property))() const \ |
| 315 |
{ \ |
| 316 |
auto prop = props[LINK_PINDEX(_param)]; \ |
| 317 |
return static_cast<const LINK_PPTYPE(_param)*>(prop); \ |
| 318 |
} \ |
| 319 |
LINK_PPTYPE(_param) * BOOST_PP_SEQ_CAT((get)(LINK_PNAME(_param))(Property))() \ |
| 320 |
{ \ |
| 321 |
auto prop = props[LINK_PINDEX(_param)]; \ |
| 322 |
return static_cast<LINK_PPTYPE(_param)*>(prop); \ |
| 323 |
} |
| 324 |
|
| 325 |
// defines get##Name##Property() and get##Name##Value() accessor |
| 326 |
BOOST_PP_SEQ_FOR_EACH(LINK_PROP_GET, _, LINK_PARAMS) |
| 327 |
|
| 328 |
PropertyLinkList* _getElementListProperty() const; |
| 329 |
const std::vector<App::DocumentObject*>& _getElementListValue() const; |
| 330 |
|
| 331 |
PropertyBool* _getShowElementProperty() const; |
| 332 |
bool _getShowElementValue() const; |
| 333 |
|
| 334 |
PropertyInteger* _getElementCountProperty() const; |
| 335 |
int _getElementCountValue() const; |
| 336 |
|
| 337 |
std::vector<DocumentObject*> getLinkedChildren(bool filter = true) const; |
| 338 |
|
| 339 |
const char* flattenSubname(const char* subname) const; |
| 340 |
void expandSubname(std::string& subname) const; |
| 341 |
|
| 342 |
DocumentObject* getLink(int depth = 0) const; |
| 343 |
|
| 344 |
Base::Matrix4D getTransform(bool transform) const; |
| 345 |
Base::Vector3d getScaleVector() const; |
| 346 |
|
| 347 |
App::GroupExtension* linkedPlainGroup() const; |
| 348 |
|
| 349 |
bool linkTransform() const; |
| 350 |
|
| 351 |
const char* getSubName() const |
| 352 |
{ |
| 353 |
parseSubName(); |
| 354 |
return !mySubName.empty() ? mySubName.c_str() : nullptr; |
| 355 |
} |
| 356 |
|
| 357 |
const std::vector<std::string>& getSubElements() const |
| 358 |
{ |
| 359 |
parseSubName(); |
| 360 |
return mySubElements; |
| 361 |
} |
| 362 |
|
| 363 |
bool extensionGetSubObject(DocumentObject*& ret, |
| 364 |
const char* subname, |
| 365 |
PyObject** pyObj = nullptr, |
| 366 |
Base::Matrix4D* mat = nullptr, |
| 367 |
bool transform = false, |
| 368 |
int depth = 0) const override; |
| 369 |
|
| 370 |
bool extensionGetSubObjects(std::vector<std::string>& ret, int reason) const override; |
| 371 |
|
| 372 |
bool extensionGetLinkedObject(DocumentObject*& ret, |
| 373 |
bool recurse, |
| 374 |
Base::Matrix4D* mat, |
| 375 |
bool transform, |
| 376 |
int depth) const override; |
| 377 |
|
| 378 |
App::DocumentObjectExecReturn* extensionExecute() override; |
| 379 |
short extensionMustExecute() override; |
| 380 |
void extensionOnChanged(const Property* p) override; |
| 381 |
void onExtendedUnsetupObject() override; |
| 382 |
void onExtendedDocumentRestored() override; |
| 383 |
|
| 384 |
int extensionSetElementVisible(const char*, bool) override; |
| 385 |
int extensionIsElementVisible(const char*) override; |
| 386 |
bool extensionHasChildElement() const override; |
| 387 |
|
| 388 |
PyObject* getExtensionPyObject() override; |
| 389 |
|
| 390 |
Property* extensionGetPropertyByName(const char* name) const override; |
| 391 |
|
| 392 |
static int getArrayIndex(const char* subname, const char** psubname = nullptr); |
| 393 |
int getElementIndex(const char* subname, const char** psubname = nullptr) const; |
| 394 |
void elementNameFromIndex(int idx, std::ostream& ss) const; |
| 395 |
|
| 396 |
DocumentObject* getContainer(); |
| 397 |
const DocumentObject* getContainer() const; |
| 398 |
|
| 399 |
void setLink(int index, |
| 400 |
DocumentObject* obj, |
| 401 |
const char* subname = nullptr, |
| 402 |
const std::vector<std::string>& subs = std::vector<std::string>()); |
| 403 |
|
| 404 |
DocumentObject* getTrueLinkedObject(bool recurse, |
| 405 |
Base::Matrix4D* mat = nullptr, |
| 406 |
int depth = 0, |
| 407 |
bool noElement = false) const; |
| 408 |
|
| 409 |
using LinkPropMap = std::map<const Property*, std::pair<LinkBaseExtension*, int>>; |
| 410 |
|
| 411 |
bool hasPlacement() const |
| 412 |
{ |
| 413 |
return getLinkPlacementProperty() || getPlacementProperty(); |
| 414 |
} |
| 415 |
|
| 416 |
void cacheChildLabel(int enable = -1) const; |
| 417 |
|
| 418 |
static bool |
| 419 |
setupCopyOnChange(App::DocumentObject* obj, |
| 420 |
App::DocumentObject* linked, |
| 421 |
std::vector<boost::signals2::scoped_connection>* copyOnChangeConns, |
| 422 |
bool checkExisting); |
| 423 |
|
| 424 |
static bool isCopyOnChangeProperty(App::DocumentObject* obj, const Property& prop); |
| 425 |
|
| 426 |
void syncCopyOnChange(); |
| 427 |
|
| 428 |
/** Options used in setOnChangeCopyObject() |
| 429 |
* Multiple options can be combined by bitwise or operator |
| 430 |
*/ |
| 431 |
enum class OnChangeCopyOptions |
| 432 |
{ |
| 433 |
/// No options set |
| 434 |
None = 0, |
| 435 |
/// If set, then exclude the input from object list to copy on change, or else, include the |
| 436 |
/// input object. |
| 437 |
Exclude = 1, |
| 438 |
/// If set , then apply the setting to all links to the input object, or else, apply only to |
| 439 |
/// this link. |
| 440 |
ApplyAll = 2, |
| 441 |
}; |
| 442 |
|
| 443 |
/** Include or exclude object from list of objects to copy on change |
| 444 |
* @param obj: input object |
| 445 |
* @param options: control options. @sa OnChangeCopyOptions. |
| 446 |
*/ |
| 447 |
void setOnChangeCopyObject(App::DocumentObject* obj, OnChangeCopyOptions options); |
| 448 |
|
| 449 |
std::vector<App::DocumentObject*> |
| 450 |
getOnChangeCopyObjects(std::vector<App::DocumentObject*>* excludes = nullptr, |
| 451 |
App::DocumentObject* src = nullptr); |
| 452 |
|
| 453 |
bool isLinkedToConfigurableObject() const; |
| 454 |
|
| 455 |
void monitorOnChangeCopyObjects(const std::vector<App::DocumentObject*>& objs); |
| 456 |
|
| 457 |
/// Check if the linked object is a copy on change |
| 458 |
bool isLinkMutated() const; |
| 459 |
|
| 460 |
protected: |
| 461 |
void |
| 462 |
_handleChangedPropertyName(Base::XMLReader& reader, const char* TypeName, const char* PropName); |
| 463 |
void parseSubName() const; |
| 464 |
void update(App::DocumentObject* parent, const Property* prop); |
| 465 |
void checkCopyOnChange(App::DocumentObject* parent, const App::Property& prop); |
| 466 |
void setupCopyOnChange(App::DocumentObject* parent, bool checkSource = false); |
| 467 |
App::DocumentObject* makeCopyOnChange(); |
| 468 |
void syncElementList(); |
| 469 |
void detachElement(App::DocumentObject* obj); |
| 470 |
void detachElements(); |
| 471 |
void checkGeoElementMap(const App::DocumentObject* obj, |
| 472 |
const App::DocumentObject* linked, |
| 473 |
PyObject** pyObj, |
| 474 |
const char* postfix) const; |
| 475 |
void updateGroup(); |
| 476 |
void slotChangedPlainGroup(const App::DocumentObject&, const App::Property&); |
| 477 |
|
| 478 |
protected: |
| 479 |
std::vector<Property*> props; |
| 480 |
std::unordered_set<const App::DocumentObject*> myHiddenElements; |
| 481 |
mutable std::vector<std::string> mySubElements; |
| 482 |
mutable std::string mySubName; |
| 483 |
|
| 484 |
std::unordered_map<const App::DocumentObject*, boost::signals2::scoped_connection> |
| 485 |
plainGroupConns; |
| 486 |
|
| 487 |
long prevLinkedObjectID = 0; |
| 488 |
|
| 489 |
mutable std::unordered_map<std::string, int> myLabelCache; // for label based subname lookup |
| 490 |
mutable bool enableLabelCache {false}; |
| 491 |
bool hasOldSubElement {false}; |
| 492 |
|
| 493 |
std::vector<boost::signals2::scoped_connection> copyOnChangeConns; |
| 494 |
std::vector<boost::signals2::scoped_connection> copyOnChangeSrcConns; |
| 495 |
bool hasCopyOnChange {true}; |
| 496 |
|
| 497 |
mutable bool checkingProperty = false; |
| 498 |
bool pauseCopyOnChange = false; |
| 499 |
|
| 500 |
boost::signals2::scoped_connection connCopyOnChangeSource; |
| 501 |
}; |
| 502 |
|
| 503 |
/////////////////////////////////////////////////////////////////////////// |
| 504 |
|
| 505 |
using LinkBaseExtensionPython = ExtensionPythonT<LinkBaseExtension>; |
| 506 |
|
| 507 |
/////////////////////////////////////////////////////////////////////////// |
| 508 |
|
| 509 |
class AppExport LinkExtension: public LinkBaseExtension |
| 510 |
{ |
| 511 |
EXTENSION_PROPERTY_HEADER_WITH_OVERRIDE(App::LinkExtension); |
| 512 |
using inherited = LinkBaseExtension; |
| 513 |
|
| 514 |
public: |
| 515 |
LinkExtension(); |
| 516 |
~LinkExtension() override = default; |
| 517 |
|
| 518 |
/** \name Helpers for defining extended parameter |
| 519 |
* |
| 520 |
* extended parameter definition |
| 521 |
* (Name, Type, Property_Type, Default, Document, Property_Name, |
| 522 |
* Derived_Property_Type, App_Property_Type, Group) |
| 523 |
* |
| 524 |
* This helper simply reuses Name as Property_Name, Property_Type as |
| 525 |
* Derived_Property_type, Prop_None as App_Propert_Type |
| 526 |
* |
| 527 |
* Note: Because PropertyView will merge linked object's properties into |
| 528 |
* ours, we set the default group name as ' Link' with a leading space to |
| 529 |
* try to make our group before others |
| 530 |
*/ |
| 531 |
//@{ |
| 532 |
|
| 533 |
#define LINK_ENAME(_param) BOOST_PP_TUPLE_ELEM(5, _param) |
| 534 |
#define LINK_ETYPE(_param) BOOST_PP_TUPLE_ELEM(6, _param) |
| 535 |
#define LINK_EPTYPE(_param) BOOST_PP_TUPLE_ELEM(7, _param) |
| 536 |
#define LINK_EGROUP(_param) BOOST_PP_TUPLE_ELEM(8, _param) |
| 537 |
|
| 538 |
#define _LINK_PROP_ADD(_add_property, _param) \ |
| 539 |
_add_property(BOOST_PP_STRINGIZE(LINK_ENAME(_param)), \ |
| 540 |
LINK_ENAME(_param), \ |
| 541 |
(LINK_PDEF(_param)), \ |
| 542 |
LINK_EGROUP(_param), \ |
| 543 |
LINK_EPTYPE(_param), \ |
| 544 |
LINK_PDOC(_param)); \ |
| 545 |
setProperty(LINK_PINDEX(_param), &LINK_ENAME(_param)); |
| 546 |
|
| 547 |
#define LINK_PROP_ADD(_1, _2, _param) _LINK_PROP_ADD(_ADD_PROPERTY_TYPE, _param); |
| 548 |
|
| 549 |
#define LINK_PROP_ADD_EXTENSION(_1, _2, _param) \ |
| 550 |
_LINK_PROP_ADD(_EXTENSION_ADD_PROPERTY_TYPE, _param); |
| 551 |
|
| 552 |
#define LINK_PROPS_ADD(_seq) BOOST_PP_SEQ_FOR_EACH(LINK_PROP_ADD, _, _seq) |
| 553 |
|
| 554 |
#define LINK_PROPS_ADD_EXTENSION(_seq) BOOST_PP_SEQ_FOR_EACH(LINK_PROP_ADD_EXTENSION, _, _seq) |
| 555 |
|
| 556 |
#define _LINK_PROP_SET(_1, _2, _param) setProperty(LINK_PINDEX(_param), &LINK_ENAME(_param)); |
| 557 |
|
| 558 |
#define LINK_PROPS_SET(_seq) BOOST_PP_SEQ_FOR_EACH(_LINK_PROP_SET, _, _seq) |
| 559 |
|
| 560 |
/// Helper for defining default extended parameter |
| 561 |
#define _LINK_PARAM_EXT(_name, _type, _ptype, _def, _doc, ...) \ |
| 562 |
((_name, _type, _ptype, _def, _doc, _name, _ptype, App::Prop_None, " Link")) |
| 563 |
|
| 564 |
/** Define default extended parameter |
| 565 |
* It simply reuses Name as Property_Name, Property_Type as |
| 566 |
* Derived_Property_Type, and App::Prop_None as App::PropertyType |
| 567 |
*/ |
| 568 |
#define LINK_PARAM_EXT(_param) BOOST_PP_EXPAND(_LINK_PARAM_EXT LINK_PARAM_##_param()) |
| 569 |
|
| 570 |
/// Helper for extended parameter with app property type |
| 571 |
#define _LINK_PARAM_EXT_ATYPE(_name, _type, _ptype, _def, _doc, _atype) \ |
| 572 |
((_name, _type, _ptype, _def, _doc, _name, _ptype, _atype, " Link")) |
| 573 |
|
| 574 |
/// Define extended parameter with app property type |
| 575 |
#define LINK_PARAM_EXT_ATYPE(_param, _atype) \ |
| 576 |
BOOST_PP_EXPAND(_LINK_PARAM_EXT_ATYPE LINK_PARAM_##_param(_atype)) |
| 577 |
|
| 578 |
/// Helper for extended parameter with derived property type |
| 579 |
#define _LINK_PARAM_EXT_TYPE(_name, _type, _ptype, _def, _doc, _dtype) \ |
| 580 |
((_name, _type, _ptype, _def, _doc, _name, _dtype, App::Prop_None, " Link")) |
| 581 |
|
| 582 |
/// Define extended parameter with derived property type |
| 583 |
#define LINK_PARAM_EXT_TYPE(_param, _dtype) \ |
| 584 |
BOOST_PP_EXPAND(_LINK_PARAM_EXT_TYPE LINK_PARAM_##_param(_dtype)) |
| 585 |
|
| 586 |
/// Helper for extended parameter with a different property name |
| 587 |
#define _LINK_PARAM_EXT_NAME(_name, _type, _ptype, _def, _doc, _pname) \ |
| 588 |
((_name, _type, _ptype, _def, _doc, _pname, _ptype, App::Prop_None, " Link")) |
| 589 |
|
| 590 |
/// Define extended parameter with a different property name |
| 591 |
#define LINK_PARAM_EXT_NAME(_param, _pname) \ |
| 592 |
BOOST_PP_EXPAND(_LINK_PARAM_EXT_NAME LINK_PARAM_##_param(_pname)) |
| 593 |
//@} |
| 594 |
|
| 595 |
#define LINK_PARAMS_EXT \ |
| 596 |
LINK_PARAM_EXT(SCALE) \ |
| 597 |
LINK_PARAM_EXT_ATYPE(SCALE_VECTOR, App::Prop_Hidden) \ |
| 598 |
LINK_PARAM_EXT(SCALES) \ |
| 599 |
LINK_PARAM_EXT(VISIBILITIES) \ |
| 600 |
LINK_PARAM_EXT(PLACEMENTS) \ |
| 601 |
LINK_PARAM_EXT(ELEMENTS) |
| 602 |
|
| 603 |
#define LINK_PROP_DEFINE(_1, _2, _param) LINK_ETYPE(_param) LINK_ENAME(_param); |
| 604 |
#define LINK_PROPS_DEFINE(_seq) BOOST_PP_SEQ_FOR_EACH(LINK_PROP_DEFINE, _, _seq) |
| 605 |
|
| 606 |
// defines the actual properties |
| 607 |
LINK_PROPS_DEFINE(LINK_PARAMS_EXT) |
| 608 |
|
| 609 |
void onExtendedDocumentRestored() override |
| 610 |
{ |
| 611 |
LINK_PROPS_SET(LINK_PARAMS_EXT); |
| 612 |
inherited::onExtendedDocumentRestored(); |
| 613 |
} |
| 614 |
}; |
| 615 |
|
| 616 |
/////////////////////////////////////////////////////////////////////////// |
| 617 |
|
| 618 |
using LinkExtensionPython = ExtensionPythonT<LinkExtension>; |
| 619 |
|
| 620 |
/////////////////////////////////////////////////////////////////////////// |
| 621 |
|
| 622 |
class AppExport Link: public App::DocumentObject, public App::LinkExtension |
| 623 |
{ |
| 624 |
PROPERTY_HEADER_WITH_EXTENSIONS(App::Link); |
| 625 |
using inherited = App::DocumentObject; |
| 626 |
|
| 627 |
public: |
| 628 |
#define LINK_PARAMS_LINK \ |
| 629 |
LINK_PARAM_EXT_TYPE(OBJECT, App::PropertyXLink) \ |
| 630 |
LINK_PARAM_EXT(CLAIM_CHILD) \ |
| 631 |
LINK_PARAM_EXT(TRANSFORM) \ |
| 632 |
LINK_PARAM_EXT(LINK_PLACEMENT) \ |
| 633 |
LINK_PARAM_EXT(PLACEMENT) \ |
| 634 |
LINK_PARAM_EXT(SHOW_ELEMENT) \ |
| 635 |
LINK_PARAM_EXT_TYPE(COUNT, App::PropertyIntegerConstraint) \ |
| 636 |
LINK_PARAM_EXT(LINK_EXECUTE) \ |
| 637 |
LINK_PARAM_EXT_ATYPE(COLORED_ELEMENTS, App::Prop_Hidden) \ |
| 638 |
LINK_PARAM_EXT(COPY_ON_CHANGE) \ |
| 639 |
LINK_PARAM_EXT_TYPE(COPY_ON_CHANGE_SOURCE, App::PropertyXLink) \ |
| 640 |
LINK_PARAM_EXT(COPY_ON_CHANGE_GROUP) \ |
| 641 |
LINK_PARAM_EXT(COPY_ON_CHANGE_TOUCHED) |
| 642 |
|
| 643 |
LINK_PROPS_DEFINE(LINK_PARAMS_LINK) |
| 644 |
|
| 645 |
Link(); |
| 646 |
|
| 647 |
const char* getViewProviderName() const override |
| 648 |
{ |
| 649 |
return "Gui::ViewProviderLink"; |
| 650 |
} |
| 651 |
|
| 652 |
void onDocumentRestored() override |
| 653 |
{ |
| 654 |
LINK_PROPS_SET(LINK_PARAMS_LINK); |
| 655 |
inherited::onDocumentRestored(); |
| 656 |
} |
| 657 |
|
| 658 |
void handleChangedPropertyName(Base::XMLReader& reader, |
| 659 |
const char* TypeName, |
| 660 |
const char* PropName) override |
| 661 |
{ |
| 662 |
_handleChangedPropertyName(reader, TypeName, PropName); |
| 663 |
} |
| 664 |
|
| 665 |
bool canLinkProperties() const override; |
| 666 |
|
| 667 |
Base::Placement getPlacementOf(const std::string& sub, DocumentObject* targetObj = nullptr) override; |
| 668 |
|
| 669 |
bool isLink() const override; |
| 670 |
|
| 671 |
bool isLinkGroup() const override; |
| 672 |
}; |
| 673 |
|
| 674 |
using LinkPython = App::FeaturePythonT<Link>; |
| 675 |
|
| 676 |
/////////////////////////////////////////////////////////////////////////// |
| 677 |
|
| 678 |
class AppExport LinkElement: public App::DocumentObject, public App::LinkBaseExtension |
| 679 |
{ |
| 680 |
PROPERTY_HEADER_WITH_EXTENSIONS(App::LinkElement); |
| 681 |
using inherited = App::DocumentObject; |
| 682 |
|
| 683 |
public: |
| 684 |
#define LINK_PARAMS_ELEMENT \ |
| 685 |
LINK_PARAM_EXT(SCALE) \ |
| 686 |
LINK_PARAM_EXT_ATYPE(SCALE_VECTOR, App::Prop_Hidden) \ |
| 687 |
LINK_PARAM_EXT_TYPE(OBJECT, App::PropertyXLink) \ |
| 688 |
LINK_PARAM_EXT(TRANSFORM) \ |
| 689 |
LINK_PARAM_EXT(LINK_PLACEMENT) \ |
| 690 |
LINK_PARAM_EXT(PLACEMENT) \ |
| 691 |
LINK_PARAM_EXT(COPY_ON_CHANGE) \ |
| 692 |
LINK_PARAM_EXT_TYPE(COPY_ON_CHANGE_SOURCE, App::PropertyXLink) \ |
| 693 |
LINK_PARAM_EXT(COPY_ON_CHANGE_GROUP) \ |
| 694 |
LINK_PARAM_EXT(COPY_ON_CHANGE_TOUCHED) |
| 695 |
|
| 696 |
// defines the actual properties |
| 697 |
LINK_PROPS_DEFINE(LINK_PARAMS_ELEMENT) |
| 698 |
|
| 699 |
LinkElement(); |
| 700 |
const char* getViewProviderName() const override |
| 701 |
{ |
| 702 |
return "Gui::ViewProviderLink"; |
| 703 |
} |
| 704 |
|
| 705 |
void onDocumentRestored() override |
| 706 |
{ |
| 707 |
LINK_PROPS_SET(LINK_PARAMS_ELEMENT); |
| 708 |
inherited::onDocumentRestored(); |
| 709 |
} |
| 710 |
|
| 711 |
bool canDelete() const; |
| 712 |
|
| 713 |
void handleChangedPropertyName(Base::XMLReader& reader, |
| 714 |
const char* TypeName, |
| 715 |
const char* PropName) override |
| 716 |
{ |
| 717 |
_handleChangedPropertyName(reader, TypeName, PropName); |
| 718 |
} |
| 719 |
|
| 720 |
bool isLink() const override; |
| 721 |
|
| 722 |
App::Link* getLinkGroup() const; |
| 723 |
|
| 724 |
Base::Placement getPlacementOf(const std::string& sub, DocumentObject* targetObj = nullptr) override; |
| 725 |
}; |
| 726 |
|
| 727 |
using LinkElementPython = App::FeaturePythonT<LinkElement>; |
| 728 |
|
| 729 |
/////////////////////////////////////////////////////////////////////////// |
| 730 |
|
| 731 |
class AppExport LinkGroup: public App::DocumentObject, public App::LinkBaseExtension |
| 732 |
{ |
| 733 |
PROPERTY_HEADER_WITH_EXTENSIONS(App::LinkGroup); |
| 734 |
using inherited = App::DocumentObject; |
| 735 |
|
| 736 |
public: |
| 737 |
#define LINK_PARAMS_GROUP \ |
| 738 |
LINK_PARAM_EXT(ELEMENTS) \ |
| 739 |
LINK_PARAM_EXT(PLACEMENT) \ |
| 740 |
LINK_PARAM_EXT(VISIBILITIES) \ |
| 741 |
LINK_PARAM_EXT(MODE) \ |
| 742 |
LINK_PARAM_EXT_ATYPE(COLORED_ELEMENTS, App::Prop_Hidden) |
| 743 |
|
| 744 |
// defines the actual properties |
| 745 |
LINK_PROPS_DEFINE(LINK_PARAMS_GROUP) |
| 746 |
|
| 747 |
LinkGroup(); |
| 748 |
|
| 749 |
const char* getViewProviderName() const override |
| 750 |
{ |
| 751 |
return "Gui::ViewProviderLink"; |
| 752 |
} |
| 753 |
|
| 754 |
void onDocumentRestored() override |
| 755 |
{ |
| 756 |
LINK_PROPS_SET(LINK_PARAMS_GROUP); |
| 757 |
inherited::onDocumentRestored(); |
| 758 |
} |
| 759 |
}; |
| 760 |
|
| 761 |
using LinkGroupPython = App::FeaturePythonT<LinkGroup>; |
| 762 |
|
| 763 |
} // namespace App |
| 764 |
|
| 765 |
ENABLE_BITMASK_OPERATORS(App::Link::OnChangeCopyOptions) |
| 766 |
|
| 767 |
/*[[[cog |
| 768 |
import LinkParams |
| 769 |
LinkParams.declare() |
| 770 |
]]]*/ |
| 771 |
|
| 772 |
namespace App |
| 773 |
{ |
| 774 |
/** Convenient class to obtain App::Link related parameters |
| 775 |
|
| 776 |
* The parameters are under group "User parameter:BaseApp/Preferences/Link" |
| 777 |
* |
| 778 |
* This class is auto generated by LinkParams.py. Modify that file |
| 779 |
* instead of this one, if you want to add any parameter. You need |
| 780 |
* to install Cog Python package for code generation: |
| 781 |
* @code |
| 782 |
* pip install cogapp |
| 783 |
* @endcode |
| 784 |
* |
| 785 |
* Once modified, you can regenerate the header and the source file, |
| 786 |
* @code |
| 787 |
* python3 -m cogapp -r Link.h Link.cpp |
| 788 |
* @endcode |
| 789 |
* |
| 790 |
* You can add a new parameter by adding lines in LinkParams.py. Available |
| 791 |
* parameter types are 'Int, UInt, String, Bool, Float'. For example, to add |
| 792 |
* a new Int type parameter, |
| 793 |
* @code |
| 794 |
* ParamInt(parameter_name, default_value, documentation, on_change=False) |
| 795 |
* @endcode |
| 796 |
* |
| 797 |
* If there is special handling on parameter change, pass in on_change=True. |
| 798 |
* And you need to provide a function implementation in Link.cpp with |
| 799 |
* the following signature. |
| 800 |
* @code |
| 801 |
* void LinkParams:on<parameter_name>Changed() |
| 802 |
* @endcode |
| 803 |
*/ |
| 804 |
class AppExport LinkParams |
| 805 |
{ |
| 806 |
public: |
| 807 |
static ParameterGrp::handle getHandle(); |
| 808 |
|
| 809 |
//@{ |
| 810 |
/// Accessor for parameter CopyOnChangeApplyToAll |
| 811 |
/// |
| 812 |
/// Stores the last user choice of whether to apply CopyOnChange setup to all link |
| 813 |
/// that links to the same configurable object |
| 814 |
static const bool& getCopyOnChangeApplyToAll(); |
| 815 |
static const bool& defaultCopyOnChangeApplyToAll(); |
| 816 |
static void removeCopyOnChangeApplyToAll(); |
| 817 |
static void setCopyOnChangeApplyToAll(const bool& v); |
| 818 |
static const char* docCopyOnChangeApplyToAll(); |
| 819 |
//@} |
| 820 |
|
| 821 |
// Auto generated code. See class document of LinkParams. |
| 822 |
}; |
| 823 |
} // namespace App |
| 824 |
//[[[end]]] |
| 825 |
|
| 826 |
|
| 827 |
#if defined(__clang__) |
| 828 |
#pragma clang diagnostic pop |
| 829 |
#endif |
| 830 |
|
| 831 |
#endif // APP_LINK_H |