| 1 |
/*************************************************************************** |
| 2 |
* Copyright (c) 2004 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 GUI_VIEWPROVIDER_H |
| 24 |
#define GUI_VIEWPROVIDER_H |
| 25 |
|
| 26 |
#include <bitset> |
| 27 |
#include <map> |
| 28 |
#include <string> |
| 29 |
#include <vector> |
| 30 |
#include <QIcon> |
| 31 |
#include <boost/signals2.hpp> |
| 32 |
#include <boost/intrusive_ptr.hpp> |
| 33 |
|
| 34 |
#include <App/Material.h> |
| 35 |
#include <App/TransactionalObject.h> |
| 36 |
#include <Base/BoundBox.h> |
| 37 |
#include <Base/Vector3D.h> |
| 38 |
|
| 39 |
#include "TreeItemMode.h" |
| 40 |
|
| 41 |
class SbVec2s; |
| 42 |
class SbVec3f; |
| 43 |
class SoNode; |
| 44 |
class SoPath; |
| 45 |
class SoSeparator; |
| 46 |
class SoEvent; |
| 47 |
class SoSwitch; |
| 48 |
class SoTransform; |
| 49 |
class SbMatrix; |
| 50 |
class SoEventCallback; |
| 51 |
class SoPickedPoint; |
| 52 |
class SoDetail; |
| 53 |
class SoFullPath; |
| 54 |
class QString; |
| 55 |
class QMenu; |
| 56 |
class QObject; |
| 57 |
|
| 58 |
|
| 59 |
namespace Base |
| 60 |
{ |
| 61 |
class Matrix4D; |
| 62 |
class Color; |
| 63 |
} // namespace Base |
| 64 |
|
| 65 |
class SoGroup; |
| 66 |
|
| 67 |
|
| 68 |
namespace Gui |
| 69 |
{ |
| 70 |
namespace TaskView |
| 71 |
{ |
| 72 |
class TaskContent; |
| 73 |
} |
| 74 |
class View3DInventorViewer; |
| 75 |
class ViewProviderPy; |
| 76 |
class ObjectItem; |
| 77 |
class MDIView; |
| 78 |
class SelectionChanges; |
| 79 |
|
| 80 |
enum ViewStatus |
| 81 |
{ |
| 82 |
UpdateData = 0, |
| 83 |
Detach = 1, |
| 84 |
isRestoring = 2, |
| 85 |
UpdatingView = 3, |
| 86 |
TouchDocument = 4, |
| 87 |
}; |
| 88 |
|
| 89 |
|
| 90 |
/** Convenience smart pointer to manage the lifetime of coin nodes. |
| 91 |
* |
| 92 |
* This class is copied from Inventor/misc/SoRefPtr.h and can be removed when the |
| 93 |
* minimum supported coin version provides this header. |
| 94 |
*/ |
| 95 |
template<typename T> |
| 96 |
class SoRefPtr |
| 97 |
{ |
| 98 |
public: |
| 99 |
SoRefPtr(void) noexcept |
| 100 |
: ptr(NULL) |
| 101 |
{} |
| 102 |
|
| 103 |
explicit SoRefPtr(T* p) |
| 104 |
: ptr(p) |
| 105 |
{ |
| 106 |
if (this->ptr) { |
| 107 |
this->ptr->ref(); |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
SoRefPtr(const SoRefPtr& other) |
| 112 |
: ptr(other.ptr) |
| 113 |
{ |
| 114 |
if (this->ptr) { |
| 115 |
this->ptr->ref(); |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
SoRefPtr(SoRefPtr&& other) noexcept |
| 120 |
: ptr(other.ptr) |
| 121 |
{ |
| 122 |
other.ptr = NULL; |
| 123 |
} |
| 124 |
|
| 125 |
~SoRefPtr(void) |
| 126 |
{ |
| 127 |
if (this->ptr) { |
| 128 |
this->ptr->unref(); |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
SoRefPtr& operator=(SoRefPtr other) noexcept |
| 133 |
{ |
| 134 |
this->swap(other); |
| 135 |
return *this; |
| 136 |
} |
| 137 |
|
| 138 |
void reset(T* p = NULL) |
| 139 |
{ |
| 140 |
SoRefPtr tmp(p); |
| 141 |
this->swap(tmp); |
| 142 |
} |
| 143 |
|
| 144 |
T* get(void) const noexcept |
| 145 |
{ |
| 146 |
return this->ptr; |
| 147 |
} |
| 148 |
T& operator*(void) const |
| 149 |
{ |
| 150 |
return *this->ptr; |
| 151 |
} |
| 152 |
T* operator->(void) const noexcept |
| 153 |
{ |
| 154 |
return this->ptr; |
| 155 |
} |
| 156 |
explicit operator bool(void) const noexcept |
| 157 |
{ |
| 158 |
return this->ptr != NULL; |
| 159 |
} |
| 160 |
|
| 161 |
void swap(SoRefPtr& other) noexcept |
| 162 |
{ |
| 163 |
using std::swap; |
| 164 |
swap(this->ptr, other.ptr); |
| 165 |
} |
| 166 |
|
| 167 |
private: |
| 168 |
T* ptr; |
| 169 |
}; |
| 170 |
|
| 171 |
/** Convenience smart pointer to wrap coin node. |
| 172 |
* |
| 173 |
* This class isn't merged with SoRefPtr because it can be removed in the future |
| 174 |
*/ |
| 175 |
template<class T> |
| 176 |
class CoinPtr: public SoRefPtr<T> |
| 177 |
{ |
| 178 |
public: |
| 179 |
using SoRefPtr<T>::SoRefPtr; |
| 180 |
|
| 181 |
CoinPtr& operator=(T* ptr) |
| 182 |
{ |
| 183 |
SoRefPtr<T>::reset(ptr); |
| 184 |
return *this; |
| 185 |
} |
| 186 |
|
| 187 |
operator T*() const |
| 188 |
{ |
| 189 |
return this->get(); |
| 190 |
} // explicit bombs |
| 191 |
}; |
| 192 |
|
| 193 |
/** Helper function to deal with bug in SoNode::removeAllChildren() |
| 194 |
* |
| 195 |
* @sa https://bitbucket.org/Coin3D/coin/pull-requests/119/fix-sochildlist-auditing/diff |
| 196 |
*/ |
| 197 |
void GuiExport coinRemoveAllChildren(SoGroup* node); |
| 198 |
|
| 199 |
/** General interface for all visual stuff in FreeCAD |
| 200 |
* This class is used to generate and handle all around |
| 201 |
* visualizing and presenting objects from the FreeCAD |
| 202 |
* App layer to the user. This class and its descendents |
| 203 |
* have to be implemented for any object type in order to |
| 204 |
* show them in the 3DView and TreeView. |
| 205 |
*/ |
| 206 |
class GuiExport ViewProvider: public App::TransactionalObject |
| 207 |
{ |
| 208 |
PROPERTY_HEADER_WITH_OVERRIDE(Gui::ViewProvider); |
| 209 |
|
| 210 |
public: |
| 211 |
enum class ToggleVisibilityMode : bool |
| 212 |
{ |
| 213 |
CanToggleVisibility = true, |
| 214 |
NoToggleVisibility = false |
| 215 |
}; |
| 216 |
|
| 217 |
/// constructor. |
| 218 |
ViewProvider(); |
| 219 |
|
| 220 |
/// destructor. |
| 221 |
~ViewProvider() override; |
| 222 |
|
| 223 |
// returns the root node of the Provider (3D) |
| 224 |
virtual SoSeparator* getRoot() const |
| 225 |
{ |
| 226 |
return pcRoot; |
| 227 |
} |
| 228 |
// return the mode switch node of the Provider (3D) |
| 229 |
SoSwitch* getModeSwitch() const |
| 230 |
{ |
| 231 |
return pcModeSwitch; |
| 232 |
} |
| 233 |
SoTransform* getTransformNode() const |
| 234 |
{ |
| 235 |
return pcTransform; |
| 236 |
} |
| 237 |
// returns the root for the Annotations. |
| 238 |
SoSeparator* getAnnotation(); |
| 239 |
// returns the root node of the Provider (3D) |
| 240 |
virtual SoSeparator* getFrontRoot() const; |
| 241 |
// returns the root node where the children gets collected(3D) |
| 242 |
virtual SoGroup* getChildRoot() const; |
| 243 |
// returns the root node of the Provider (3D) |
| 244 |
virtual SoSeparator* getBackRoot() const; |
| 245 |
/// Indicate whether to be added to scene graph or not |
| 246 |
virtual bool canAddToSceneGraph() const |
| 247 |
{ |
| 248 |
return true; |
| 249 |
} |
| 250 |
// Indicate whether to be added to object group (true) or only to scene graph (false) |
| 251 |
virtual bool isPartOfPhysicalObject() const |
| 252 |
{ |
| 253 |
return true; |
| 254 |
} |
| 255 |
|
| 256 |
/** deliver the children belonging to this object |
| 257 |
* this method is used to deliver the objects to |
| 258 |
* the 3DView which should be grouped under its |
| 259 |
* scene graph. This affects the visibility and the 3D |
| 260 |
* position of the object. |
| 261 |
*/ |
| 262 |
virtual std::vector<App::DocumentObject*> claimChildren3D() const; |
| 263 |
|
| 264 |
/** @name Selection handling |
| 265 |
* This group of methods do the selection handling. |
| 266 |
* Here you can define how the selection for your ViewProfider |
| 267 |
* works. |
| 268 |
*/ |
| 269 |
//@{ |
| 270 |
|
| 271 |
/// indicates if the ViewProvider use the new Selection model |
| 272 |
virtual bool useNewSelectionModel() const; |
| 273 |
virtual bool isSelectable() const |
| 274 |
{ |
| 275 |
return true; |
| 276 |
} |
| 277 |
/// called when the selection changes for the view provider |
| 278 |
virtual void onSelectionChanged(const SelectionChanges&) |
| 279 |
{} |
| 280 |
/// return a hit element given the picked point which contains the full node path |
| 281 |
virtual bool getElementPicked(const SoPickedPoint*, std::string& subname) const; |
| 282 |
/// return a hit element to the selection path or 0 |
| 283 |
virtual std::string getElement(const SoDetail*) const |
| 284 |
{ |
| 285 |
return {}; |
| 286 |
} |
| 287 |
/// return the coin node detail of the subelement |
| 288 |
virtual SoDetail* getDetail(const char*) const |
| 289 |
{ |
| 290 |
return nullptr; |
| 291 |
} |
| 292 |
|
| 293 |
/** return the coin node detail and path to the node of the subelement |
| 294 |
* |
| 295 |
* @param subname: dot separated string reference to the sub element |
| 296 |
* @param pPath: output coin path leading to the returned element detail |
| 297 |
* @param append: If true, pPath will be first appended with the root node and |
| 298 |
* the mode switch node of this view provider. |
| 299 |
* |
| 300 |
* @return the coin detail of the subelement |
| 301 |
* |
| 302 |
* If this view provider links to other view provider, then the |
| 303 |
* implementation of getDetailPath() shall also append all intermediate |
| 304 |
* nodes starting just after the mode switch node up till the mode switch of |
| 305 |
* the linked view provider. |
| 306 |
*/ |
| 307 |
virtual bool getDetailPath(const char* subname, SoFullPath* pPath, bool append, SoDetail*& det) const; |
| 308 |
|
| 309 |
/** partial rendering setup |
| 310 |
* |
| 311 |
* @param subelements: a list of dot separated string refer to the sub element |
| 312 |
* @param clear: if true, remove the subelement from partial rendering. |
| 313 |
* If else, add the subelement for rendering. |
| 314 |
* |
| 315 |
* @return Return the number of subelement found |
| 316 |
* |
| 317 |
* Partial rendering only works if there is at least one SoFCSelectRoot node |
| 318 |
* in this view provider |
| 319 |
*/ |
| 320 |
int partialRender(const std::vector<std::string>& subelements, bool clear); |
| 321 |
|
| 322 |
virtual std::vector<Base::Vector3d> getModelPoints(const SoPickedPoint*) const; |
| 323 |
/// return the highlight lines for a given element or the whole shape |
| 324 |
virtual std::vector<Base::Vector3d> getSelectionShape(const char* Element) const |
| 325 |
{ |
| 326 |
(void)Element; |
| 327 |
return {}; |
| 328 |
} |
| 329 |
|
| 330 |
/** Return the bound box of this view object |
| 331 |
* |
| 332 |
* This method shall work regardless whether the current view object is |
| 333 |
* visible or not. |
| 334 |
*/ |
| 335 |
Base::BoundBox3d getBoundingBox( |
| 336 |
const char* subname = nullptr, |
| 337 |
bool transform = true, |
| 338 |
MDIView* view = nullptr |
| 339 |
) const; |
| 340 |
|
| 341 |
/** |
| 342 |
* Get called if the object is about to get deleted. |
| 343 |
* Here you can delete other objects, switch their visibility or prevent the deletion of the |
| 344 |
* object. |
| 345 |
* @param subNames list of selected subelements |
| 346 |
* @return true if the deletion is approved by the view provider. |
| 347 |
*/ |
| 348 |
virtual bool onDelete(const std::vector<std::string>& subNames); |
| 349 |
/** Called before deletion |
| 350 |
* |
| 351 |
* Unlike onDelete(), this function is guaranteed to be called before |
| 352 |
* deletion, either by Document::remObject(), or on document deletion. |
| 353 |
*/ |
| 354 |
virtual void beforeDelete(); |
| 355 |
/** |
| 356 |
* @brief Asks the view provider if the given object that is part of its |
| 357 |
* outlist can be removed from there without breaking it. |
| 358 |
* @param obj is part of the outlist of the object associated to the view provider |
| 359 |
* @return true if the removal is approved by the view provider. |
| 360 |
*/ |
| 361 |
virtual bool canDelete(App::DocumentObject* obj) const; |
| 362 |
//@} |
| 363 |
|
| 364 |
|
| 365 |
/** @name Methods used by the Tree |
| 366 |
* If you want to take control over the |
| 367 |
* appearance of your object in the tree you |
| 368 |
* can reimplement these methods. |
| 369 |
*/ |
| 370 |
//@{ |
| 371 |
/// deliver the icon shown in the tree view |
| 372 |
virtual QIcon getIcon() const; |
| 373 |
|
| 374 |
/** |
| 375 |
* @brief Whether the viewprovider should allow to toggle the visibility. |
| 376 |
* |
| 377 |
* Some document objects are not rendered and for those document objects, |
| 378 |
* it makes no sense to be able to toggle the visibility. Examples are |
| 379 |
* VarSet and Spreadsheet. |
| 380 |
* |
| 381 |
* Note that "rendered" should be seen broadly here. Objects such as |
| 382 |
* TechDraw pages, templates, views, and dimensions are not rendered by |
| 383 |
* Coin but are "rendered" on the TechDraw page and hence this function can |
| 384 |
* return true for those items. |
| 385 |
*/ |
| 386 |
bool canToggleVisibility() const |
| 387 |
{ |
| 388 |
return toggleVisibilityMode == ToggleVisibilityMode::CanToggleVisibility; |
| 389 |
} |
| 390 |
|
| 391 |
/** @name Methods used by the Tree |
| 392 |
* If you want to take control over the |
| 393 |
* viewprovider specific overlay icons that will be drawn with color |
| 394 |
* regardless of whether the icon is greyed out or not, such as status, you |
| 395 |
* can reimplement this method. |
| 396 |
*/ |
| 397 |
virtual QIcon mergeColorfulOverlayIcons(const QIcon& orig) const; |
| 398 |
|
| 399 |
/** deliver the children belonging to this object |
| 400 |
* this method is used to deliver the objects to |
| 401 |
* the tree framework which should be grouped under its |
| 402 |
* label. Obvious is the usage in the group but it can |
| 403 |
* be used for any kind of grouping needed for a special |
| 404 |
* purpose. |
| 405 |
*/ |
| 406 |
virtual std::vector<App::DocumentObject*> claimChildren() const; |
| 407 |
//@} |
| 408 |
|
| 409 |
/** deliver the children belonging to this object recursively. |
| 410 |
*/ |
| 411 |
virtual std::vector<App::DocumentObject*> claimChildrenRecursive() const; |
| 412 |
//@} |
| 413 |
|
| 414 |
/** @name Drag and drop |
| 415 |
* To enable drag and drop you have to re-implement \ref canDragObjects() and |
| 416 |
* \ref canDropObjects() to return true. For finer control you can also re-implement |
| 417 |
* \ref canDragObject() or \ref canDropObject() to filter certain object types, by |
| 418 |
* default these methods don't filter any types. |
| 419 |
* To take action of drag and drop the method \ref dragObject() and \ref dropObject() |
| 420 |
* must be re-implemented, too. |
| 421 |
*/ |
| 422 |
//@{ |
| 423 |
/** Check whether children can be removed from the view provider by drag and drop */ |
| 424 |
virtual bool canDragObjects() const; |
| 425 |
/** Check whether the object can be removed from the view provider by drag and drop */ |
| 426 |
virtual bool canDragObject(App::DocumentObject*) const; |
| 427 |
/** Check whether the object can be removed from the view provider by drag and drop to a |
| 428 |
* determined target*/ |
| 429 |
virtual bool canDragObjectToTarget(App::DocumentObject* obj, App::DocumentObject* target) const; |
| 430 |
/** Remove a child from the view provider by drag and drop */ |
| 431 |
virtual void dragObject(App::DocumentObject*); |
| 432 |
/** Check whether objects can be added to the view provider by drag and drop or drop only */ |
| 433 |
virtual bool canDropObjects() const; |
| 434 |
/** Check whether the object can be dropped to the view provider by drag and drop or drop only*/ |
| 435 |
virtual bool canDropObject(App::DocumentObject*) const; |
| 436 |
/** Return false to force drop only operation for a given object*/ |
| 437 |
virtual bool canDragAndDropObject(App::DocumentObject*) const; |
| 438 |
/** Add an object to the view provider by drag and drop */ |
| 439 |
virtual void dropObject(App::DocumentObject*); |
| 440 |
/** Query object dropping with full qualified name |
| 441 |
* |
| 442 |
* Tree view now calls this function instead of canDropObject(), and may |
| 443 |
* query for objects from other document. The default implementation |
| 444 |
* (actually in ViewProviderDocumentObject) inhibites cross document |
| 445 |
* dropping, and calls canDropObject(obj) for the rest. Override this |
| 446 |
* function to enable cross document linking. |
| 447 |
* |
| 448 |
* @param obj: the object being dropped |
| 449 |
* |
| 450 |
* @param owner: the (grand)parent object of the dropping object. Maybe |
| 451 |
* null. This may not be the top parent object, as tree view will try to |
| 452 |
* find a parent of the dropping object relative to this object to avoid |
| 453 |
* cyclic dependency |
| 454 |
* |
| 455 |
* @param subname: subname reference to the dropping object |
| 456 |
* |
| 457 |
* @param elements: non-object sub-elements, e.g. Faces, Edges, selected |
| 458 |
* when the object is being dropped |
| 459 |
* |
| 460 |
* @return Return whether the dropping action is allowed. |
| 461 |
* */ |
| 462 |
virtual bool canDropObjectEx( |
| 463 |
App::DocumentObject* obj, |
| 464 |
App::DocumentObject* owner, |
| 465 |
const char* subname, |
| 466 |
const std::vector<std::string>& elements |
| 467 |
) const; |
| 468 |
/* Check whether the object accept reordering of its children during drop.*/ |
| 469 |
virtual bool acceptReorderingObjects() const |
| 470 |
{ |
| 471 |
return false; |
| 472 |
}; |
| 473 |
|
| 474 |
/// return a subname referencing the sub-object holding the dropped objects |
| 475 |
virtual std::string getDropPrefix() const |
| 476 |
{ |
| 477 |
return {}; |
| 478 |
} |
| 479 |
|
| 480 |
/** Add an object with full qualified name to the view provider by drag and drop |
| 481 |
* |
| 482 |
* @param obj: the object being dropped |
| 483 |
* |
| 484 |
* @param owner: the (grand)parent object of the dropping object. Maybe |
| 485 |
* null. This may not be the top parent object, as tree view will try to |
| 486 |
* find a parent of the dropping object relative to this object to avoid |
| 487 |
* cyclic dependency |
| 488 |
* |
| 489 |
* @param subname: subname reference to the dropping object |
| 490 |
* |
| 491 |
* @param elements: non-object sub-elements, e.g. Faces, Edges, selected |
| 492 |
* when the object is being dropped |
| 493 |
* |
| 494 |
* @return Optionally returns a subname reference locating the dropped |
| 495 |
* object, which may or may not be the actual dropped object, e.g. it may be |
| 496 |
* a link. |
| 497 |
*/ |
| 498 |
virtual std::string dropObjectEx( |
| 499 |
App::DocumentObject* obj, |
| 500 |
App::DocumentObject* owner, |
| 501 |
const char* subname, |
| 502 |
const std::vector<std::string>& elements |
| 503 |
); |
| 504 |
/** Replace an object to the view provider by drag and drop |
| 505 |
* |
| 506 |
* @param oldObj: object to be replaced |
| 507 |
* @param newObj: object to replace with |
| 508 |
* |
| 509 |
* @return Returns 0 if not found, 1 if succeeded, -1 if not supported |
| 510 |
*/ |
| 511 |
virtual int replaceObject(App::DocumentObject* oldObj, App::DocumentObject* newObj); |
| 512 |
//@} |
| 513 |
|
| 514 |
/** Tell the tree view if this object should appear there */ |
| 515 |
virtual bool showInTree() const |
| 516 |
{ |
| 517 |
return true; |
| 518 |
} |
| 519 |
/** Tell the tree view to remove children items from the tree root*/ |
| 520 |
virtual bool canRemoveChildrenFromRoot() const |
| 521 |
{ |
| 522 |
return true; |
| 523 |
} |
| 524 |
/** Tell if the tree item should be auto collapsed*/ |
| 525 |
bool isAutoCollapseOnDeactivation() const |
| 526 |
{ |
| 527 |
return autoCollapseOnDeactivation; |
| 528 |
} |
| 529 |
|
| 530 |
/** @name Signals of the view provider */ |
| 531 |
//@{ |
| 532 |
/// signal on icon change |
| 533 |
boost::signals2::signal<void()> signalChangeIcon; |
| 534 |
/// signal on tooltip change |
| 535 |
boost::signals2::signal<void(const QString&)> signalChangeToolTip; |
| 536 |
/// signal on status tip change |
| 537 |
boost::signals2::signal<void(const QString&)> signalChangeStatusTip; |
| 538 |
/// signal on highlight change |
| 539 |
boost::signals2::signal<void(bool, Gui::HighlightMode)> signalChangeHighlight; |
| 540 |
//@} |
| 541 |
|
| 542 |
/** update the content of the ViewProvider |
| 543 |
* this method have to implement the recalculation |
| 544 |
* of the ViewProvider. There are different reasons to |
| 545 |
* update. E.g. only the view attribute has changed, or |
| 546 |
* the data has manipulated. |
| 547 |
*/ |
| 548 |
virtual void update(const App::Property*); |
| 549 |
virtual void updateData(const App::Property*); |
| 550 |
bool isUpdatesEnabled() const; |
| 551 |
void setUpdatesEnabled(bool enable); |
| 552 |
|
| 553 |
/// return the status bits |
| 554 |
unsigned long getStatus() const |
| 555 |
{ |
| 556 |
return StatusBits.to_ulong(); |
| 557 |
} |
| 558 |
bool testStatus(ViewStatus pos) const |
| 559 |
{ |
| 560 |
return StatusBits.test((size_t)pos); |
| 561 |
} |
| 562 |
void setStatus(ViewStatus pos, bool on) |
| 563 |
{ |
| 564 |
StatusBits.set((size_t)pos, on); |
| 565 |
} |
| 566 |
|
| 567 |
std::string toString() const; |
| 568 |
PyObject* getPyObject() override; |
| 569 |
|
| 570 |
/** @name Display mode methods |
| 571 |
*/ |
| 572 |
//@{ |
| 573 |
std::string getActiveDisplayMode() const; |
| 574 |
/// set the display mode |
| 575 |
virtual void setDisplayMode(const char* ModeName); |
| 576 |
/// get the default display mode |
| 577 |
virtual const char* getDefaultDisplayMode() const; |
| 578 |
/// returns a list of all possible display modes |
| 579 |
virtual std::vector<std::string> getDisplayModes() const; |
| 580 |
/// Hides the view provider |
| 581 |
virtual void hide(); |
| 582 |
/// Shows the view provider |
| 583 |
virtual void show(); |
| 584 |
/// checks whether the view provider is visible or not |
| 585 |
virtual bool isShow() const; |
| 586 |
void setVisible(bool); |
| 587 |
bool isVisible() const; |
| 588 |
void setLinkVisible(bool); |
| 589 |
bool isLinkVisible() const; |
| 590 |
/// Overrides the display mode with mode. |
| 591 |
virtual void setOverrideMode(const std::string& mode); |
| 592 |
const std::string getOverrideMode(); |
| 593 |
//@} |
| 594 |
|
| 595 |
/** @name Color management methods |
| 596 |
*/ |
| 597 |
//@{ |
| 598 |
virtual std::map<std::string, Base::Color> getElementColors(const char* element = nullptr) const |
| 599 |
{ |
| 600 |
(void)element; |
| 601 |
return {}; |
| 602 |
} |
| 603 |
virtual void setElementColors(const std::map<std::string, Base::Color>& colors) |
| 604 |
{ |
| 605 |
(void)colors; |
| 606 |
} |
| 607 |
static const std::string& hiddenMarker(); |
| 608 |
static const char* hasHiddenMarker(const char* subname); |
| 609 |
//@} |
| 610 |
|
| 611 |
/** @name Edit methods |
| 612 |
* if the Viewprovider goes in edit mode |
| 613 |
* you can handle most of the events in the viewer by yourself |
| 614 |
*/ |
| 615 |
//@{ |
| 616 |
// the below enum is reflected in 'userEditModes' std::map in Application.h |
| 617 |
// so it is possible for the user to choose a default one through GUI |
| 618 |
// if you add a mode here, consider to make it accessible there too |
| 619 |
enum EditMode |
| 620 |
{ |
| 621 |
Default = 0, |
| 622 |
Transform, |
| 623 |
Cutting, |
| 624 |
Color, |
| 625 |
}; |
| 626 |
|
| 627 |
protected: |
| 628 |
/// is called by the document when the provider goes in edit mode |
| 629 |
virtual bool setEdit(int ModNum); |
| 630 |
/// is called when you lose the edit mode |
| 631 |
virtual void unsetEdit(int ModNum); |
| 632 |
/// return the edit mode or -1 if nothing is being edited |
| 633 |
int getEditingMode() const; |
| 634 |
|
| 635 |
public: |
| 636 |
virtual ViewProvider* startEditing(int ModNum = 0); |
| 637 |
bool isEditing() const; |
| 638 |
void finishEditing(); |
| 639 |
/// adjust viewer settings when editing a view provider |
| 640 |
virtual void setEditViewer(View3DInventorViewer*, int ModNum); |
| 641 |
/// restores viewer settings when leaving editing mode |
| 642 |
virtual void unsetEditViewer(View3DInventorViewer*); |
| 643 |
//@} |
| 644 |
|
| 645 |
/** @name Task panel |
| 646 |
* With this interface the ViewProvider can steer the |
| 647 |
* appearance of widgets in the task view |
| 648 |
*/ |
| 649 |
//@{ |
| 650 |
/// get a list of TaskBoxes associated with this object |
| 651 |
virtual void getTaskViewContent(std::vector<Gui::TaskView::TaskContent*>&) const |
| 652 |
{} |
| 653 |
//@} |
| 654 |
|
| 655 |
/// is called when the provider is in edit and a "Select All" command was issued |
| 656 |
/// Provider shall return 'false' is it ignores the command, 'true' otherwise |
| 657 |
virtual bool selectAll() |
| 658 |
{ |
| 659 |
return false; |
| 660 |
} |
| 661 |
/// is called when the provider is in edit and a key event occurs. Only ESC ends edit. |
| 662 |
virtual bool keyPressed(bool pressed, int key); |
| 663 |
/// Is called by the tree if the user double clicks on the object. It returns the string |
| 664 |
/// for the transaction that will be shown in the undo/redo dialog. |
| 665 |
/// If null is returned then no transaction will be opened. |
| 666 |
virtual const char* getTransactionText() const |
| 667 |
{ |
| 668 |
return nullptr; |
| 669 |
} |
| 670 |
/// is called by the tree if the user double clicks on the object |
| 671 |
virtual bool doubleClicked() |
| 672 |
{ |
| 673 |
return false; |
| 674 |
} |
| 675 |
/// is called when the provider is in edit and the mouse is moved |
| 676 |
virtual bool mouseMove(const SbVec2s& cursorPos, View3DInventorViewer* viewer); |
| 677 |
/// is called when the Provider is in edit and the mouse is clicked |
| 678 |
virtual bool mouseButtonPressed( |
| 679 |
int button, |
| 680 |
bool pressed, |
| 681 |
const SbVec2s& cursorPos, |
| 682 |
const View3DInventorViewer* viewer |
| 683 |
); |
| 684 |
|
| 685 |
virtual bool mouseWheelEvent(int delta, const SbVec2s& cursorPos, const View3DInventorViewer* viewer); |
| 686 |
/// set up the context-menu with the supported edit modes |
| 687 |
virtual void setupContextMenu(QMenu*, QObject*, const char*); |
| 688 |
|
| 689 |
/** @name direct handling methods |
| 690 |
* This group of methods is to direct influence the |
| 691 |
* appearance of the viewed content. It's only for fast |
| 692 |
* interactions! If you want to set the visual parameters |
| 693 |
* you have to do it on the object viewed by this provider! |
| 694 |
*/ |
| 695 |
//@{ |
| 696 |
/// set the viewing transformation of the provider |
| 697 |
virtual void setTransformation(const Base::Matrix4D& rcMatrix); |
| 698 |
virtual void setTransformation(const SbMatrix& rcMatrix); |
| 699 |
static SbMatrix convert(const Base::Matrix4D& rcMatrix); |
| 700 |
static Base::Matrix4D convert(const SbMatrix& sbMat); |
| 701 |
//@} |
| 702 |
|
| 703 |
virtual MDIView* getMDIView() const |
| 704 |
{ |
| 705 |
return nullptr; |
| 706 |
} |
| 707 |
|
| 708 |
public: |
| 709 |
// this method is called by the viewer when the ViewProvider is in edit |
| 710 |
static void eventCallback(void* ud, SoEventCallback* node); |
| 711 |
|
| 712 |
// restoring the object from document: |
| 713 |
// this may be of interest to extensions, hence call them |
| 714 |
void Restore(Base::XMLReader& reader) override; |
| 715 |
bool isRestoring() |
| 716 |
{ |
| 717 |
return testStatus(Gui::isRestoring); |
| 718 |
} |
| 719 |
|
| 720 |
|
| 721 |
/** @name Display mask modes |
| 722 |
* Mainly controls an SoSwitch node which selects the display mask modes. |
| 723 |
* The number of display mask modes doesn't necessarily match with the number |
| 724 |
* of display modes. |
| 725 |
* E.g. various display modes like Gaussian curvature, mean curvature or gray |
| 726 |
* values are displayed by one display mask mode that handles color values. |
| 727 |
*/ |
| 728 |
//@{ |
| 729 |
/// Adds a new display mask mode |
| 730 |
void addDisplayMaskMode(SoNode* node, const char* type); |
| 731 |
/// Activates the display mask mode \a type |
| 732 |
void setDisplayMaskMode(const char* type); |
| 733 |
/// Get the node to the display mask mode \a type |
| 734 |
SoNode* getDisplayMaskMode(const char* type) const; |
| 735 |
/// Returns a list of added display mask modes |
| 736 |
std::vector<std::string> getDisplayMaskModes() const; |
| 737 |
void setDefaultMode(int); |
| 738 |
int getDefaultMode() const; |
| 739 |
//@} |
| 740 |
|
| 741 |
virtual void setRenderCacheMode(int); |
| 742 |
|
| 743 |
protected: |
| 744 |
/** Helper method to check that the node is valid, i.e. it must not cause |
| 745 |
* and infinite recursion. |
| 746 |
*/ |
| 747 |
bool checkRecursion(SoNode*); |
| 748 |
/** Helper method to get picked entities while editing. |
| 749 |
* It's in the responsibility of the caller to delete the returned instance. |
| 750 |
*/ |
| 751 |
SoPickedPoint* getPointOnRay(const SbVec2s& pos, const View3DInventorViewer* viewer) const; |
| 752 |
/** Helper method to get picked entities while editing. |
| 753 |
* It's in the responsibility of the caller to delete the returned instance. |
| 754 |
*/ |
| 755 |
SoPickedPoint* getPointOnRay( |
| 756 |
const SbVec3f& pos, |
| 757 |
const SbVec3f& dir, |
| 758 |
const View3DInventorViewer* viewer |
| 759 |
) const; |
| 760 |
/// Reimplemented from subclass |
| 761 |
void onBeforeChange(const App::Property* prop) override; |
| 762 |
/// Reimplemented from subclass |
| 763 |
void onChanged(const App::Property* prop) override; |
| 764 |
|
| 765 |
/** @name Methods used by the Tree |
| 766 |
* If you want to take control over the |
| 767 |
* viewprovider specific overlay icons, that will be grayed out together |
| 768 |
* with the base icon, you can reimplement this method. |
| 769 |
*/ |
| 770 |
virtual QIcon mergeGreyableOverlayIcons(const QIcon& orig) const; |
| 771 |
|
| 772 |
/// Turn on mode switch |
| 773 |
virtual void setModeSwitch(); |
| 774 |
|
| 775 |
void setToggleVisibility(ToggleVisibilityMode mode) |
| 776 |
{ |
| 777 |
toggleVisibilityMode = mode; |
| 778 |
} |
| 779 |
|
| 780 |
protected: |
| 781 |
/// The root Separator of the ViewProvider |
| 782 |
SoSeparator* pcRoot; |
| 783 |
/// this is transformation for the provider |
| 784 |
SoTransform* pcTransform; |
| 785 |
const char* sPixmap; |
| 786 |
/// this is the mode switch, all the different viewing modes are collected here |
| 787 |
SoSwitch* pcModeSwitch; |
| 788 |
/// The root separator for annotations |
| 789 |
SoSeparator* pcAnnotation {nullptr}; |
| 790 |
ViewProviderPy* pyViewObject {nullptr}; |
| 791 |
bool autoCollapseOnDeactivation {true}; |
| 792 |
std::string overrideMode; |
| 793 |
std::bitset<32> StatusBits; |
| 794 |
/// whether visibility can toggled |
| 795 |
ToggleVisibilityMode toggleVisibilityMode; |
| 796 |
|
| 797 |
friend class ViewProviderPy; |
| 798 |
|
| 799 |
private: |
| 800 |
int _iActualMode {-1}; |
| 801 |
int _iEditMode {-1}; |
| 802 |
int viewOverrideMode {-1}; |
| 803 |
std::string _sCurrentMode; |
| 804 |
std::map<std::string, int> _sDisplayMaskModes; |
| 805 |
}; |
| 806 |
|
| 807 |
} // namespace Gui |
| 808 |
|
| 809 |
#endif // GUI_VIEWPROVIDER_H |