BIM: Add support for deactivation active object to BIM Views Tree (#21570)
* BIM: Use checkbox in model tree for Activation/Deactivation of WP * BIM: Set active object after deactivating current object if it exists Currently we can get into a scenario where user can activate two working planes, one after another. For example, Level, and then Level001. If they activate both, and then deactivate Level001, working plane switches back to Level. But, we didn't set the object as the active one, so user didn't have clear information that they can deactivate it, only the working plane was switching it. So this patch sets the object as the active one, if it exists. * BIM: Add support for deactivation active object to BIM Views Tree As the title says - it adds the checkbox that's similarly done in Part workbench, so user can select/deselect the item and if they had previous active object, it will also fall back to the previous object. Also, moved out part of the common logic from ArchBuildingPart and BimViews to utils. * BIM: Handle correct context on activating WP for NativeIFC/BIM * BIM: Remove redundant logic from BIM Views upon double click As all of the logic is being handled now in `activate` function in BimViews, this logic is redundant * BIM: Rename button for taskbar and BIM Views from Activate to Active
This commit is contained in:
@@ -1068,4 +1068,69 @@ def pyopen(file, mode='r', buffering=-1, encoding=None, errors=None, newline=Non
|
||||
encoding = 'utf-8'
|
||||
return open(file, mode, buffering, encoding, errors, newline, closefd, opener)
|
||||
|
||||
def toggle_working_plane(obj, action=None, restore=False, dialog=None):
|
||||
"""Toggle the active state of a working plane object.
|
||||
|
||||
This function handles the common logic for activating and deactivating
|
||||
working plane objects like BuildingParts and WorkingPlaneProxies.
|
||||
It can be used by different modules that need to implement similar
|
||||
working plane activation behavior.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
obj : App::DocumentObject
|
||||
The object to activate or deactivate as a working plane.
|
||||
action : QAction, optional
|
||||
The action button that triggered this function, to update its checked state.
|
||||
restore : bool, optional
|
||||
If True, will restore the previous working plane when deactivating.
|
||||
Defaults to False.
|
||||
dialog : QDialog, optional
|
||||
If provided, will update the checked state of the activate button in the dialog.
|
||||
|
||||
Returns
|
||||
-------
|
||||
bool
|
||||
True if the object was activated, False if it was deactivated.
|
||||
"""
|
||||
import FreeCADGui
|
||||
import Draft
|
||||
|
||||
# Determine the appropriate context based on object type
|
||||
context = "Arch"
|
||||
obj_type = get_type(obj)
|
||||
if obj_type == "IfcBuildingStorey":
|
||||
context = "NativeIFC"
|
||||
|
||||
# Check if the object is already active in its context
|
||||
is_active_arch = (FreeCADGui.ActiveDocument.ActiveView.getActiveObject("Arch") == obj)
|
||||
is_active_ifc = (FreeCADGui.ActiveDocument.ActiveView.getActiveObject("NativeIFC") == obj)
|
||||
is_active = is_active_arch or is_active_ifc
|
||||
if is_active:
|
||||
# Deactivate the object
|
||||
if is_active_arch:
|
||||
FreeCADGui.ActiveDocument.ActiveView.setActiveObject("Arch", None)
|
||||
if is_active_ifc:
|
||||
FreeCADGui.ActiveDocument.ActiveView.setActiveObject("NativeIFC", None)
|
||||
|
||||
if hasattr(obj, "ViewObject") and hasattr(obj.ViewObject, "Proxy") and \
|
||||
hasattr(obj.ViewObject.Proxy, "setWorkingPlane"):
|
||||
obj.ViewObject.Proxy.setWorkingPlane(restore=True)
|
||||
if action:
|
||||
action.setChecked(False)
|
||||
if dialog and hasattr(dialog, "buttonActive"):
|
||||
dialog.buttonActive.setChecked(False)
|
||||
return False
|
||||
else:
|
||||
# Activate the object
|
||||
FreeCADGui.ActiveDocument.ActiveView.setActiveObject(context, obj)
|
||||
if hasattr(obj, "ViewObject") and hasattr(obj.ViewObject, "Proxy") and \
|
||||
hasattr(obj.ViewObject.Proxy, "setWorkingPlane"):
|
||||
obj.ViewObject.Proxy.setWorkingPlane()
|
||||
if action:
|
||||
action.setChecked(True)
|
||||
if dialog and hasattr(dialog, "buttonActive"):
|
||||
dialog.buttonActive.setChecked(True)
|
||||
return True
|
||||
|
||||
## @}
|
||||
|
||||
Reference in New Issue
Block a user