Browse Source

removed old files

master
Youen Toupin 2 years ago
parent
commit
c8374e1ea2
  1. 25
      InitGui.py
  2. 21
      ahb_cmd_animate.py
  3. 29
      ahb_cmd_set_active_stage.py
  4. 43
      ahb_cmd_set_part_stage.py
  5. 21
      ahb_cmd_switch_visibility_mode.py
  6. 127
      ahb_context.py
  7. 1
      ahb_locator.py

25
InitGui.py

@ -23,7 +23,6 @@ class AssemblyHandbookWorkbench(Gui.Workbench):
dev = True # indicates development mode (enables additional tools, log, debug checks, etc.) dev = True # indicates development mode (enables additional tools, log, debug checks, etc.)
context = None
docObserver = None docObserver = None
docLinkObserver = None docLinkObserver = None
partsCache = None partsCache = None
@ -42,9 +41,6 @@ class AssemblyHandbookWorkbench(Gui.Workbench):
""" """
code which should be computed when a user switch to this workbench code which should be computed when a user switch to this workbench
""" """
if self.context is None:
self.initializeContext()
import ahb_document_observer import ahb_document_observer
if self.docLinkObserver is None: if self.docLinkObserver is None:
self.docLinkObserver = ahb_document_observer.DocLinkObserver() self.docLinkObserver = ahb_document_observer.DocLinkObserver()
@ -75,31 +71,15 @@ class AssemblyHandbookWorkbench(Gui.Workbench):
self.appendContextMenu("", contextMenu) self.appendContextMenu("", contextMenu)
self.appendContextMenu("", "Separator") self.appendContextMenu("", "Separator")
def initializeContext(self):
import ahb_context
self.context = ahb_context.AHB_Context()
def registerCommands(self): def registerCommands(self):
toolbox = [] toolbox = []
#self.importModule('ahb_cmd_export_csv') #self.importModule('ahb_cmd_export_csv')
#toolbox.append("AHB_exportCsv") #toolbox.append("AHB_exportCsv")
#self.importModule('ahb_cmd_set_active_stage')
#toolbox.append("AHB_setActiveStage")
#self.importModule('ahb_cmd_set_part_stage')
#toolbox.append("AHB_setPartStage")
#self.importModule('ahb_cmd_switch_visibility_mode')
#toolbox.append("AHB_switchVisibilityMode")
self.importModule('ahb_cmd_render') self.importModule('ahb_cmd_render')
toolbox.append("AHB_render") toolbox.append("AHB_render")
#self.importModule('ahb_cmd_animate')
#toolbox.append("AHB_animate")
self.importModule('ahb_cmd_new_step') self.importModule('ahb_cmd_new_step')
toolbox.append("AHB_new_step") toolbox.append("AHB_new_step")
@ -126,11 +106,7 @@ class AssemblyHandbookWorkbench(Gui.Workbench):
self.removeToolbar("Assembly Handbook") self.removeToolbar("Assembly Handbook")
self.removeMenu("Assembly Handbook") self.removeMenu("Assembly Handbook")
self.context.setAnimationActive(False)
import importlib import importlib
import ahb_context
importlib.reload(ahb_context)
import ahb_parts_cache import ahb_parts_cache
importlib.reload(ahb_parts_cache) importlib.reload(ahb_parts_cache)
@ -140,7 +116,6 @@ class AssemblyHandbookWorkbench(Gui.Workbench):
importlib.reload(ahb_techdraw_extensions) importlib.reload(ahb_techdraw_extensions)
self.techDrawExtensions = ahb_techdraw_extensions.TechDrawExtensions() self.techDrawExtensions = ahb_techdraw_extensions.TechDrawExtensions()
self.initializeContext()
self.registerCommands() self.registerCommands()
pass pass

21
ahb_cmd_animate.py

@ -1,21 +0,0 @@
from typing import Optional
import FreeCADGui as Gui
import FreeCAD as App
class AHB_Animate:
def GetResources(self):
return {"MenuText": "Animate",
"ToolTip": "Animate active stage to show all build stages",
"Pixmap": ""
}
def IsActive(self):
return True
def Activated(self, stageId: Optional[int] = None):
workbench = Gui.getWorkbench("AssemblyHandbookWorkbench")
workbench.context.setAnimationActive(not workbench.context.getAnimationActive())
from ahb_command import AHB_CommandWrapper
AHB_CommandWrapper.addGuiCommand('AHB_animate', AHB_Animate())

29
ahb_cmd_set_active_stage.py

@ -1,29 +0,0 @@
import FreeCADGui as Gui
import FreeCAD as App
from PySide import QtGui
class AHB_SetActiveStage:
def GetResources(self):
return {"MenuText": "Set active stage",
"ToolTip": "Sets the stage which is the active stage, or creates a new stage if it doesn't exist",
"Pixmap": ""
}
def IsActive(self):
return True
def Activated(self, stageId = None):
if stageId is None:
reply = QtGui.QInputDialog.getText(None, "Set Active Stage", "Enter the stage number:")
if reply[1]:
# user clicked OK
stageId = int(reply[0])
else:
return
workbench = Gui.getWorkbench("AssemblyHandbookWorkbench")
workbench.context.setActiveStage(stageId)
from ahb_command import AHB_CommandWrapper
AHB_CommandWrapper.addGuiCommand('AHB_setActiveStage', AHB_SetActiveStage())

43
ahb_cmd_set_part_stage.py

@ -1,43 +0,0 @@
from typing import Optional
import FreeCADGui as Gui
import FreeCAD as App
class AHB_SetPartStage:
def GetResources(self):
return {"MenuText": "Set part stage",
"ToolTip": "Sets the stage for this part to the currently active stage",
"Pixmap": ""
}
def IsActive(self):
return True
def Activated(self, stageId: Optional[int] = None):
workbench = Gui.getWorkbench("AssemblyHandbookWorkbench")
if stageId is None:
stageId = workbench.context.getActiveStage()
if stageId is None:
raise BaseException("You must activate a stage before using this command")
obj: App.DocumentObject
for obj in Gui.Selection.getSelection():
if obj is not None and obj.TypeId in ['Part::Feature','App::Part']:
if not "AssemblyHandbook_Stage" in obj.PropertiesList:
obj.addProperty("App::PropertyInteger", "AssemblyHandbook_Stage", "AssemblyHandbook")
if not "AssemblyHandbook_RenderLines" in obj.PropertiesList:
obj.addProperty("App::PropertyBool", "AssemblyHandbook_RenderLines", "AssemblyHandbook")
obj.AssemblyHandbook_RenderLines = True
obj.AssemblyHandbook_Stage = stageId
# if we are setting the stage on a part, remove the property from all features of that part
if obj.TypeId == 'App::Part':
for feature in obj.Group:
if 'AssemblyHandbook_Stage' in feature.PropertiesList:
feature.removeProperty('AssemblyHandbook_Stage')
workbench.context.onPartStageChanged(obj)
from ahb_command import AHB_CommandWrapper
AHB_CommandWrapper.addGuiCommand('AHB_setPartStage', AHB_SetPartStage())

21
ahb_cmd_switch_visibility_mode.py

@ -1,21 +0,0 @@
from typing import Optional
import FreeCADGui as Gui
import FreeCAD as App
class AHB_SwitchVisibilityMode:
def GetResources(self):
return {"MenuText": "Switch visibility",
"ToolTip": "Switch visibility mode",
"Pixmap": ""
}
def IsActive(self):
return True
def Activated(self, stageId: Optional[int] = None):
workbench = Gui.getWorkbench("AssemblyHandbookWorkbench")
workbench.context.setAllStagesVisible(not workbench.context.getAllStagesVisible())
from ahb_command import AHB_CommandWrapper
AHB_CommandWrapper.addGuiCommand('AHB_switchVisibilityMode', AHB_SwitchVisibilityMode())

127
ahb_context.py

@ -1,127 +0,0 @@
from typing import Optional
import FreeCADGui as Gui
import FreeCAD as App
from PySide.QtCore import QTimer
import random
def _rgb(r, g, b):
return r/255.0, g/255.0, b/255.0, 0.0
_colors = [
_rgb(94, 224, 174),
_rgb(223, 234, 70),
_rgb(35, 120, 200),
_rgb(188, 80, 33),
_rgb(26, 242, 69),
_rgb(13, 41, 107),
_rgb(153, 9, 52),
_rgb(211, 119, 0),
_rgb(34, 130, 7),
_rgb(221, 79, 249)
]
class AHB_Context:
_activeStageId: int = None
_allStagesVisible: bool = True
_animationActive: bool = False
_timeSinceLastStageUpdate: int = 0
def setActiveStage(self, stageId):
self._activeStageId = stageId
self._updateVisibility()
def getActiveStage(self):
return self._activeStageId
def getAllStages(self):
allStages = set()
doc = App.ActiveDocument
for obj in doc.Objects:
if obj.TypeId in ['Part::Feature', 'App::Part']:
if 'AssemblyHandbook_Stage' in obj.PropertiesList:
allStages.add(obj.AssemblyHandbook_Stage)
allStages = list(allStages)
allStages.sort()
return allStages
def onPartStageChanged(self, part: Optional[App.DocumentObject]):
allStages = self.getAllStages()
doc = App.ActiveDocument
if part is not None and not 'AssemblyHandbook_Stage' in part.PropertiesList:
part.ViewObject.ShapeColor = (0.8,0.8,0.8,0.0)
for obj in doc.Objects:
if obj.TypeId in ['Part::Feature', 'App::Part']:
if 'AssemblyHandbook_Stage' in obj.PropertiesList:
stageIndex = allStages.index(obj.AssemblyHandbook_Stage)
if obj.TypeId == 'Part::Feature':
obj.ViewObject.ShapeColor = _colors[stageIndex % len(_colors)]
elif obj.TypeId == 'App::Part':
for feature in obj.Group:
if feature.TypeId == 'Part::Feature':
feature.ViewObject.ShapeColor = _colors[stageIndex % len(_colors)]
self._updateVisibility()
def setAllStagesVisible(self, allStagesVisible):
self._allStagesVisible = allStagesVisible
self._updateVisibility()
def getAllStagesVisible(self):
return self._allStagesVisible
def _updateVisibility(self):
activeStageId = self.getActiveStage()
doc = App.ActiveDocument
for obj in doc.Objects:
if obj.TypeId == 'Part::Feature' in ['Part::Feature', 'App::Part']:
if 'AssemblyHandbook_Stage' in obj.PropertiesList:
obj.ViewObject.Visibility = self._allStagesVisible or activeStageId is None or obj.AssemblyHandbook_Stage <= activeStageId
def setAnimationActive(self, animationActive):
if self._animationActive == animationActive: return
self._animationActive = animationActive
self._updateAnimation()
def getAnimationActive(self):
return self._animationActive
def _updateAnimation(self):
if not self._animationActive: return
allStages = self.getAllStages()
if len(allStages) > 1 and self._timeSinceLastStageUpdate >= 1000:
self._timeSinceLastStageUpdate = 0
activeStageId = self.getActiveStage() or 0
stageIndex = allStages.index(activeStageId) if activeStageId in allStages else 0
stageIndex = (stageIndex + 1) % len(allStages)
self.setActiveStage(allStages[stageIndex])
tickResolution = 33
import math
from pivy import coin
cam = Gui.ActiveDocument.ActiveView.getCameraNode()
"""rot = coin.SbRotation()
rot.setValue(coin.SbVec3f(0, 0, 1), math.pi * tickResolution / 1000.0)
nrot = cam.orientation.getValue() * rot
cam.orientation = nrot"""
center = coin.SbVec3f(1000,0,750)
v = cam.position.getValue() - center
v[2] = 0
dist = v.length()
height = cam.position.getValue()[2]
angle = math.atan2(v[1], v[0])
angle = angle + 0.3 * tickResolution / 1000.0
cam.position = coin.SbVec3f(center[0] + math.cos(angle)*dist, center[1] + math.sin(angle)*dist, height)
cam.pointAt(center, coin.SbVec3f(0,0,1))
self._timeSinceLastStageUpdate = self._timeSinceLastStageUpdate + tickResolution
QTimer.singleShot(tickResolution, self._updateAnimation)

1
ahb_locator.py

@ -0,0 +1 @@
# this module is only used to help other modules to locate its folder
Loading…
Cancel
Save