forked from youen/assembly_handbook
Youen Toupin
2 years ago
7 changed files with 1 additions and 266 deletions
@ -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()) |
@ -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()) |
@ -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()) |
@ -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()) |
@ -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) |
Loading…
Reference in new issue