Rebased
This commit is contained in:
@@ -1188,7 +1188,7 @@ class ViewProviderBuildingPart:
|
||||
menu.addAction(actionCloneUp)
|
||||
|
||||
def activate(self, action=None):
|
||||
from draftutils.utils import toggle_working_plane
|
||||
from draftutils.gui_utils import toggle_working_plane
|
||||
|
||||
vobj = self.Object.ViewObject
|
||||
|
||||
|
||||
@@ -463,7 +463,7 @@ class BIM_Views:
|
||||
|
||||
@staticmethod
|
||||
def activate(dialog=None):
|
||||
from draftutils.utils import toggle_working_plane
|
||||
from draftutils.gui_utils import toggle_working_plane
|
||||
|
||||
vm = findWidget()
|
||||
if vm:
|
||||
|
||||
@@ -976,4 +976,74 @@ def end_all_events():
|
||||
QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents)
|
||||
|
||||
|
||||
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.
|
||||
"""
|
||||
|
||||
# Determine the appropriate context based on object type
|
||||
context = "Arch"
|
||||
obj_type = utils.get_type(obj)
|
||||
if obj_type == "IfcBuildingStorey":
|
||||
context = "NativeIFC"
|
||||
|
||||
# Check if the object is already active in its context
|
||||
is_active_arch = Gui.ActiveDocument.ActiveView.getActiveObject("Arch") == obj
|
||||
is_active_ifc = Gui.ActiveDocument.ActiveView.getActiveObject("NativeIFC") == obj
|
||||
is_active = is_active_arch or is_active_ifc
|
||||
if is_active:
|
||||
# Deactivate the object
|
||||
if is_active_arch:
|
||||
Gui.ActiveDocument.ActiveView.setActiveObject("Arch", None)
|
||||
if is_active_ifc:
|
||||
Gui.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
|
||||
Gui.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
|
||||
|
||||
|
||||
## @}
|
||||
|
||||
@@ -1136,76 +1136,4 @@ def pyopen(
|
||||
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