| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| __title__ = "FreeCAD FEM base constraint ViewProvider" |
| __author__ = "Markus Hovorka, Bernd Hahnebach" |
| __url__ = "https://www.freecad.org" |
|
|
| |
| |
| |
|
|
|
|
| import FreeCAD |
| import FreeCADGui |
|
|
| import FemGui |
|
|
| from femobjects.base_fempythonobject import _PropHelper |
|
|
| False if FemGui.__name__ else True |
|
|
|
|
| class _GuiPropHelper(_PropHelper): |
| """ |
| Helper class to manage property data inside proxy objects. |
| Based on the App version, but viewprovider addProperty does |
| not take keyword args, hence we use positional arguments here |
| """ |
|
|
| def __init__(self, **kwds): |
| super().__init__(**kwds) |
|
|
| def add_to_object(self, obj): |
| obj.addProperty(self.info["type"], self.info["name"], self.info["group"], self.info["doc"]) |
| obj.setPropertyStatus(self.name, "LockDynamic") |
| setattr(obj, self.name, self.value) |
|
|
|
|
| class VPBaseFemObject: |
| """Proxy View Provider for FEM FeaturePythons base constraint.""" |
|
|
| def __init__(self, vobj): |
| vobj.Proxy = self |
|
|
| |
| |
| def getIcon(self): |
| """after load from FCStd file, self.icon does not exist, return constant path instead""" |
| |
| if not hasattr(self.Object, "Proxy"): |
| FreeCAD.Console.PrintMessage(f"{self.Object.Name}, has no Proxy.\n") |
| return "" |
| if not hasattr(self.Object.Proxy, "Type"): |
| FreeCAD.Console.PrintMessage( |
| f"{self.Object.Name}: Proxy does has not have attribute Type.\n" |
| ) |
| return "" |
| if isinstance(self.Object.Proxy.Type, str) and self.Object.Proxy.Type.startswith("Fem::"): |
| icon_path = "/icons/{}.svg".format(self.Object.Proxy.Type.replace("Fem::", "FEM_")) |
| FreeCAD.Console.PrintLog(f"{self.Object.Name} --> {icon_path}\n") |
| return f":/{icon_path}" |
| else: |
| FreeCAD.Console.PrintError(f"No icon returned for {self.Object.Name}\n") |
| FreeCAD.Console.PrintMessage(f"{self.Object.Proxy.Type}\n") |
| return "" |
|
|
| def attach(self, vobj): |
| self.Object = vobj.Object |
| self.ViewObject = vobj |
|
|
| def setEdit(self, vobj, mode=0, TaskPanel=None, hide_mesh=True): |
| if TaskPanel is None: |
| |
| |
| return False |
| if hide_mesh: |
| |
| for obj in vobj.Object.Document.Objects: |
| if ( |
| obj.isDerivedFrom("Fem::FemMeshObject") |
| or obj.isDerivedFrom("Fem::FemPostPlaneFunction") |
| or obj.isDerivedFrom("Fem::FemPostSphereFunction") |
| ): |
| obj.ViewObject.hide() |
| |
| task = TaskPanel(vobj.Object) |
| FreeCADGui.Control.showDialog(task) |
| return True |
|
|
| def unsetEdit(self, vobj, mode=0): |
| FreeCADGui.Control.closeDialog() |
| return True |
|
|
| def doubleClicked(self, vobj): |
| guidoc = FreeCADGui.getDocument(vobj.Object.Document) |
| |
| |
| if not guidoc.getInEdit(): |
| guidoc.setEdit(vobj.Object.Name) |
| else: |
| from PySide.QtGui import QMessageBox |
|
|
| message = "Active Task Dialog found! Please close this one before opening a new one!" |
| QMessageBox.critical(None, "Error in tree view", message) |
| FreeCAD.Console.PrintError(message + "\n") |
| return True |
|
|
| |
| |
| |
| def dumps(self): |
| return None |
|
|
| def loads(self, state): |
| return None |
|
|