| 1 |
from Base.Metadata import constmethod |
| 2 |
from Base.BoundBox import BoundBox |
| 3 |
from App.ExtensionContainer import ExtensionContainer |
| 4 |
from typing import Any, Final, List, Optional |
| 5 |
import enum |
| 6 |
|
| 7 |
class ViewProvider(ExtensionContainer): |
| 8 |
""" |
| 9 |
This is the ViewProvider base class |
| 10 |
|
| 11 |
Author: Werner Mayer ([email protected]) |
| 12 |
Licence: LGPL |
| 13 |
""" |
| 14 |
|
| 15 |
class ToggleVisibilityMode(enum.Enum): |
| 16 |
CanToggleVisibility = "CanToggleVisibility" |
| 17 |
NoToggleVisibility = "NoToggleVisibility" |
| 18 |
|
| 19 |
def addProperty( |
| 20 |
self, |
| 21 |
*, |
| 22 |
type: str, |
| 23 |
name: str, |
| 24 |
group: str, |
| 25 |
doc: str, |
| 26 |
attr: int = 0, |
| 27 |
read_only: bool = False, |
| 28 |
hidden: bool = False, |
| 29 |
locked: bool = False, |
| 30 |
) -> "ViewProvider": |
| 31 |
""" |
| 32 |
addProperty(type, name, group, doc, attr=0, read_only=False, hidden=False, locked=False) -> ViewProvider |
| 33 |
|
| 34 |
Add a generic property. |
| 35 |
|
| 36 |
type : str |
| 37 |
Property type. |
| 38 |
name : str |
| 39 |
Property name. Optional. |
| 40 |
group : str |
| 41 |
Property group. Optional. |
| 42 |
attr : int |
| 43 |
Property attributes. |
| 44 |
read_only : bool |
| 45 |
Read only property. |
| 46 |
hidden : bool |
| 47 |
Hidden property. |
| 48 |
locked : bool |
| 49 |
Locked property. |
| 50 |
""" |
| 51 |
... |
| 52 |
|
| 53 |
def removeProperty(self, name: str) -> bool: |
| 54 |
""" |
| 55 |
removeProperty(name) -> bool |
| 56 |
|
| 57 |
Remove a generic property. |
| 58 |
Only user-defined properties can be removed, not built-in ones. |
| 59 |
|
| 60 |
name : str |
| 61 |
Property name. |
| 62 |
""" |
| 63 |
... |
| 64 |
|
| 65 |
def supportedProperties(self) -> list: |
| 66 |
""" |
| 67 |
supportedProperties() -> list |
| 68 |
|
| 69 |
A list of supported property types. |
| 70 |
""" |
| 71 |
... |
| 72 |
|
| 73 |
def show(self) -> None: |
| 74 |
""" |
| 75 |
show() -> None |
| 76 |
|
| 77 |
Show the object. |
| 78 |
""" |
| 79 |
... |
| 80 |
|
| 81 |
def hide(self) -> None: |
| 82 |
""" |
| 83 |
hide() -> None |
| 84 |
|
| 85 |
Hide the object. |
| 86 |
""" |
| 87 |
... |
| 88 |
|
| 89 |
def isVisible(self) -> bool: |
| 90 |
""" |
| 91 |
isVisible() -> bool |
| 92 |
|
| 93 |
Check if the object is visible. |
| 94 |
""" |
| 95 |
... |
| 96 |
|
| 97 |
def canDragObject(self, obj: Any = None) -> bool: |
| 98 |
""" |
| 99 |
canDragObject(obj=None) -> bool |
| 100 |
|
| 101 |
Check whether the child object can be removed by dragging. |
| 102 |
If 'obj' is not given, check without filter by any particular object. |
| 103 |
|
| 104 |
obj : App.DocumentObject |
| 105 |
Object to be dragged. |
| 106 |
""" |
| 107 |
... |
| 108 |
|
| 109 |
def dragObject(self, obj: Any) -> None: |
| 110 |
""" |
| 111 |
dragObject(obj) -> None |
| 112 |
|
| 113 |
Remove a child object by dropping. |
| 114 |
|
| 115 |
obj : App.DocumentObject |
| 116 |
Object to be dragged. |
| 117 |
""" |
| 118 |
... |
| 119 |
|
| 120 |
def canDropObject( |
| 121 |
self, *, obj: Any = None, owner: Any = None, subname: str, elem: Optional[List[str]] = None |
| 122 |
) -> bool: |
| 123 |
""" |
| 124 |
canDropObject(obj=None, owner=None, subname, elem=None) -> bool |
| 125 |
|
| 126 |
Check whether the child object can be added by dropping. |
| 127 |
If 'obj' is not given, check without filter by any particular object. |
| 128 |
|
| 129 |
obj : App.DocumentObject |
| 130 |
Object to be dropped. |
| 131 |
owner : App.DocumentObject |
| 132 |
Parent object of the dropping object. |
| 133 |
subname : str |
| 134 |
Subname reference to the dropping object. Optional. |
| 135 |
elem : sequence of str |
| 136 |
Non-objects subelements selected when the object is |
| 137 |
being dropped. |
| 138 |
""" |
| 139 |
... |
| 140 |
|
| 141 |
def dropObject( |
| 142 |
self, *, obj: Any, owner: Any = None, subname: str, elem: Optional[List[str]] = None |
| 143 |
) -> str: |
| 144 |
""" |
| 145 |
dropObject(obj, owner=None, subname, elem=None) -> str |
| 146 |
|
| 147 |
Add a child object by dropping. |
| 148 |
|
| 149 |
obj : App.DocumentObject |
| 150 |
Object to be dropped. |
| 151 |
owner : App.DocumentObject |
| 152 |
Parent object of the dropping object. |
| 153 |
subname : str |
| 154 |
Subname reference to the dropping object. Optional. |
| 155 |
elem : sequence of str |
| 156 |
Non-objects subelements selected when the object is |
| 157 |
being dropped. |
| 158 |
""" |
| 159 |
... |
| 160 |
|
| 161 |
def canDragAndDropObject(self, obj: Any) -> bool: |
| 162 |
""" |
| 163 |
canDragAndDropObject(obj) -> bool |
| 164 |
|
| 165 |
Check whether the child object can be removed from |
| 166 |
other parent and added here by drag and drop. |
| 167 |
|
| 168 |
obj : App.DocumentObject |
| 169 |
Object to be dragged and dropped. |
| 170 |
""" |
| 171 |
... |
| 172 |
|
| 173 |
def replaceObject(self, oldObj: Any, newObj: Any) -> int: |
| 174 |
""" |
| 175 |
replaceObject(oldObj, newObj) -> int |
| 176 |
|
| 177 |
Replace a child object. |
| 178 |
Returns 1 if succeeded, 0 if not found, -1 if not supported. |
| 179 |
|
| 180 |
oldObj : App.DocumentObject |
| 181 |
Old object. |
| 182 |
newObj : App.DocumentObject |
| 183 |
New object. |
| 184 |
""" |
| 185 |
... |
| 186 |
|
| 187 |
def doubleClicked(self) -> bool: |
| 188 |
""" |
| 189 |
doubleClicked() -> bool |
| 190 |
|
| 191 |
Trigger double clicking the corresponding tree item of this view object. |
| 192 |
""" |
| 193 |
... |
| 194 |
|
| 195 |
def addDisplayMode(self, obj: Any, mode: str) -> None: |
| 196 |
""" |
| 197 |
addDisplayMode(obj, mode) -> None |
| 198 |
|
| 199 |
Add a new display mode to the view provider. |
| 200 |
|
| 201 |
obj : coin.SoNode |
| 202 |
Display mode. |
| 203 |
mode : str |
| 204 |
Name of the display mode. |
| 205 |
""" |
| 206 |
... |
| 207 |
|
| 208 |
def listDisplayModes(self) -> list: |
| 209 |
""" |
| 210 |
listDisplayModes() -> list |
| 211 |
|
| 212 |
Show a list of all display modes. |
| 213 |
""" |
| 214 |
... |
| 215 |
|
| 216 |
def toString(self) -> str: |
| 217 |
""" |
| 218 |
toString() -> str |
| 219 |
|
| 220 |
Return a string representation of the Inventor node. |
| 221 |
""" |
| 222 |
... |
| 223 |
|
| 224 |
def setTransformation(self, trans: Any) -> None: |
| 225 |
""" |
| 226 |
setTransformation(trans) -> None |
| 227 |
|
| 228 |
Set a transformation on the Inventor node. |
| 229 |
|
| 230 |
trans : Base.Placement, Base.Matrix |
| 231 |
""" |
| 232 |
... |
| 233 |
|
| 234 |
@constmethod |
| 235 |
def claimChildren(self) -> list: |
| 236 |
""" |
| 237 |
claimChildren() -> list |
| 238 |
|
| 239 |
Returns list of objects that are to be grouped in tree under this object. |
| 240 |
""" |
| 241 |
... |
| 242 |
|
| 243 |
@constmethod |
| 244 |
def claimChildrenRecursive(self) -> list: |
| 245 |
""" |
| 246 |
claimChildrenRecursive() -> list |
| 247 |
|
| 248 |
Returns list of objects that are to be grouped in tree under this object recursively. |
| 249 |
""" |
| 250 |
... |
| 251 |
|
| 252 |
def partialRender(self, sub: Any = None, clear: bool = False) -> int: |
| 253 |
""" |
| 254 |
partialRender(sub=None, clear=False) -> int |
| 255 |
|
| 256 |
Render only part of the object. |
| 257 |
|
| 258 |
sub: None, str, sequence of str |
| 259 |
Refer to the subelement. If it is None then reset the partial rendering. |
| 260 |
clear: bool |
| 261 |
True to add, or False to remove the subelement(s) for rendering. |
| 262 |
""" |
| 263 |
... |
| 264 |
|
| 265 |
def getElementColors(self, elementName: Optional[str] = None) -> dict: |
| 266 |
""" |
| 267 |
getElementColors(elementName) -> dict |
| 268 |
|
| 269 |
Get a dictionary of the form {elementName : (r,g,b,a)}. |
| 270 |
If no element name is given a dictionary with all the elements is returned. |
| 271 |
|
| 272 |
elementName : str |
| 273 |
Name of the element. Optional. |
| 274 |
""" |
| 275 |
... |
| 276 |
|
| 277 |
def setElementColors(self, colors: dict) -> None: |
| 278 |
""" |
| 279 |
setElementColors(colors) -> None |
| 280 |
|
| 281 |
Set element colors. |
| 282 |
|
| 283 |
colors: dict |
| 284 |
Color dictionary of the form {elementName:(r,g,b,a)}. |
| 285 |
""" |
| 286 |
... |
| 287 |
|
| 288 |
@constmethod |
| 289 |
def getElementPicked(self, pickPoint: Any) -> str: |
| 290 |
""" |
| 291 |
getElementPicked(pickPoint) -> str |
| 292 |
|
| 293 |
Return the picked subelement. |
| 294 |
|
| 295 |
pickPoint : coin.SoPickedPoint |
| 296 |
""" |
| 297 |
... |
| 298 |
|
| 299 |
@constmethod |
| 300 |
def getDetailPath(self, subelement: str, path: Any, append: bool = True) -> Any: |
| 301 |
""" |
| 302 |
getDetailPath(subelement, path, append=True) -> coin.SoDetail or None |
| 303 |
|
| 304 |
Return Coin detail and path of an subelement. |
| 305 |
|
| 306 |
subname: str |
| 307 |
Dot separated string reference to the sub element. |
| 308 |
pPath: coin.SoPath |
| 309 |
Output coin path leading to the returned element detail. |
| 310 |
append: bool |
| 311 |
If True, path will be first appended with the root node and the mode |
| 312 |
switch node of this view provider. |
| 313 |
""" |
| 314 |
... |
| 315 |
|
| 316 |
@constmethod |
| 317 |
def signalChangeIcon(self) -> None: |
| 318 |
""" |
| 319 |
signalChangeIcon() -> None |
| 320 |
|
| 321 |
Trigger icon changed signal. |
| 322 |
""" |
| 323 |
... |
| 324 |
|
| 325 |
def getBoundingBox( |
| 326 |
self, subName: Optional[str] = None, transform: bool = True, view: Any = None |
| 327 |
) -> BoundBox: |
| 328 |
""" |
| 329 |
getBoundingBox(subName, transform=True, view) -> Base.BoundBox |
| 330 |
|
| 331 |
Obtain the bounding box of this view object. |
| 332 |
|
| 333 |
subName : str |
| 334 |
Name referring a sub-object. Optional. |
| 335 |
transform: bool |
| 336 |
Whether to apply the transformation matrix of this view provider. |
| 337 |
view: View3DInventorPy |
| 338 |
Default to active view. Optional. |
| 339 |
""" |
| 340 |
... |
| 341 |
Annotation: Any = ... |
| 342 |
"""A pivy Separator to add a custom scenegraph to this ViewProvider.""" |
| 343 |
|
| 344 |
Icon: Final[Any] = ... |
| 345 |
"""The icon of this ViewProvider.""" |
| 346 |
|
| 347 |
RootNode: Any = ... |
| 348 |
"""A pivy Separator with the root of this ViewProvider.""" |
| 349 |
|
| 350 |
SwitchNode: Any = ... |
| 351 |
"""A pivy SoSwitch for the display mode switch of this ViewProvider.""" |
| 352 |
|
| 353 |
DefaultMode: int = 0 |
| 354 |
"""Get/Set the default display mode in turns of coin node index.""" |
| 355 |
|
| 356 |
IV: Final[str] = "" |
| 357 |
"""Represents the whole ViewProvider as an Inventor string.""" |
| 358 |
|
| 359 |
CanRemoveChildrenFromRoot: Final[bool] = False |
| 360 |
"""Tells the tree view whether to remove the children item from root or not.""" |
| 361 |
|
| 362 |
LinkVisibility: bool = False |
| 363 |
"""Get/set visibilities of all links to this view object.""" |
| 364 |
|
| 365 |
DropPrefix: Final[str] = "" |
| 366 |
"""Subname referencing the sub-object for holding dropped object.""" |
| 367 |
|
| 368 |
ToggleVisibility: ToggleVisibilityMode = ToggleVisibilityMode.CanToggleVisibility |
| 369 |
"""Get/set whether the viewprovider can toggle the visibility of |
| 370 |
the object.""" |