38 import communication
as com
40 from PySide2.QtWidgets
import QMessageBox
44 PATH_TO_ICONS = path.join(FreeCAD.getHomePath(),
"Mod",
"Animate",
"Resources",
105 fp.ViewObject.Proxy.setProperties(fp.ViewObject)
114 def onDocumentClosed(self):
116 if isinstance(self.
cmd_server, com.CommandServer):
117 FreeCAD.Console.PrintMessage(
"Closing server with it's document\n")
133 if not hasattr(fp,
"Address"):
134 fp.addProperty(
"App::PropertyString",
"Address",
"Server settings",
135 "IP address where the server will listen for " 136 +
"connection.\nValid values are IPv4 and " 137 +
"IPv6 addresses or 'localhost'string." 138 ).Address =
"localhost" 139 if not hasattr(fp,
"Port"):
140 fp.addProperty(
"App::PropertyIntegerConstraint",
"Port",
141 "Server settings",
"Port where the server will " 142 +
"listen for connections.\n" +
143 "Valid port numbers are in range <0 | 65535>,\n" 144 +
"but some may be already taken!" 145 ).Port = (54321, 0, 65535, 1)
147 fp.Port = (fp.Port, 0, 65535, 1)
148 if not hasattr(fp,
"Running"):
149 fp.addProperty(
"App::PropertyBool",
"Running",
"Server settings",
150 "If Server Running is true, then Server listens " 151 +
"for new connections." 155 fp.setEditorMode(
"Placement", 2)
158 fp.setEditorMode(
"Running", 1)
162 self.
cmd_server = com.startServer(fp.Address, fp.Port)
163 if self.
cmd_server == com.SERVER_ERROR_INVALID_ADDRESS:
164 fp.ViewObject.Proxy._icon = path.join(PATH_TO_ICONS,
166 QMessageBox.warning(
None,
'Error while starting server',
167 "The address was not in supported format.")
169 elif self.
cmd_server == com.SERVER_ERROR_PORT_OCCUPIED:
170 fp.ViewObject.Proxy._icon = path.join(PATH_TO_ICONS,
172 QMessageBox.warning(
None,
'Error while starting server',
173 "The port requested is already occupied.")
176 fp.setEditorMode(
"Address", 1)
177 fp.setEditorMode(
"Port", 1)
179 fp.ViewObject.Proxy._icon = path.join(PATH_TO_ICONS,
183 import AnimateDocumentObserver
185 FreeCAD.animate_observer.addServerToNotify(self,
186 FreeCAD.ActiveDocument.Name)
244 _icon = path.join(PATH_TO_ICONS,
"Server.png")
275 if vp.Object.Running:
276 FreeCAD.Console.PrintMessage(
"Deleting server safely.\n")
277 vp.Object.Proxy.cmd_server.close()
296 if not vp.Object.Running:
297 vp.Object.Proxy.cmd_server = com.startServer(vp.Object.Address,
299 if isinstance(vp.Object.Proxy.cmd_server, int):
300 if vp.Object.Proxy.cmd_server == \
301 com.SERVER_ERROR_INVALID_ADDRESS:
302 QMessageBox.warning(
None,
'Error while starting server',
303 "The address was not in supported " 305 elif vp.Object.Proxy.cmd_server == \
306 com.SERVER_ERROR_PORT_OCCUPIED:
307 QMessageBox.warning(
None,
'Error while starting server',
308 "The port requested is already " 311 vp.Object.setEditorMode(
"Address", 1)
312 vp.Object.setEditorMode(
"Port", 1)
313 vp.Object.Running =
True 314 self.
_icon = path.join(PATH_TO_ICONS,
"ServerRunning.png")
315 elif vp.Object.Running:
316 vp.Object.Proxy.cmd_server.close()
317 vp.Object.setEditorMode(
"Address", 0)
318 vp.Object.setEditorMode(
"Port", 0)
319 vp.Object.Running =
False 320 self.
_icon = path.join(PATH_TO_ICONS,
"Server.png")
336 if vp.Object.Running:
337 action = menu.addAction(
"Disconnect Server")
341 action = menu.addAction(
"Connect Server")
365 vp.setEditorMode(
"AngularDeflection", 2)
366 vp.setEditorMode(
"BoundingBox", 2)
367 vp.setEditorMode(
"Deviation", 2)
368 vp.setEditorMode(
"DisplayMode", 2)
369 vp.setEditorMode(
"DrawStyle", 2)
370 vp.setEditorMode(
"Lighting", 2)
371 vp.setEditorMode(
"LineColor", 2)
372 vp.setEditorMode(
"LineWidth", 2)
373 vp.setEditorMode(
"PointColor", 2)
374 vp.setEditorMode(
"PointSize", 2)
375 vp.setEditorMode(
"Selectable", 2)
376 vp.setEditorMode(
"SelectionStyle", 2)
377 vp.setEditorMode(
"ShapeColor", 2)
378 vp.setEditorMode(
"Transparency", 2)
379 vp.setEditorMode(
"Visibility", 2)
381 if vp.Object.Running:
382 self.
_icon = path.join(PATH_TO_ICONS,
"ServerRunning.png")
384 self.
_icon = path.join(PATH_TO_ICONS,
"Server.png")
405 return {
'Pixmap': path.join(PATH_TO_ICONS,
"ServerCmd.png"),
406 'MenuText':
"Server",
407 'ToolTip':
"Create Server instance."}
418 doc = FreeCAD.ActiveDocument
419 a = doc.addObject(
"Part::FeaturePython",
"Server")
436 if FreeCAD.ActiveDocument
is None:
def __init__(self, vp)
Initialization method for ViewProviderServerProxy.
Proxy class for a Gui.ViewProviderDocumentObject Server.ViewObject.
def getIcon(self)
Method used to get a path to an icon which will appear in the tree view.
def setupContextMenu(self, vp, menu)
Method called by the FreeCAD to customize a context menu for a Server.
def doubleClicked(self, vp)
Method called when FeaturePython Server is double-clicked in the Tree View.
def __init__(self, fp)
Initialization method for ServerProxy.
def addObserver()
Adds an AnimateDocumentObserver between FreeCAD's document observers safely.
def onDelete(self, vp, subelements)
Method called when FeaturePython Server is about to be deleted.
def onDocumentRestored(self, fp)
Method called when document is restored to make sure everything is as it was.
def GetResources(self)
Method used by FreeCAD to retrieve resources to use for this command.
def Activated(self)
Method used as a callback when the toolbar button or the menu item is clicked.
cmd_server
A CommandServer instance to handle external commands.
Proxy class for a FeaturePython Server instance.
ServerCommand class specifying Animate workbench's Server button/command.
def setProperties(self, fp)
Method to set properties during initialization or document restoration.
def __setstate__(self, state)
Necessary method to avoid errors when trying to restore unserializable objects.
_icon
A path to the icon image to be displayed in the Tree View.
def __getstate__(self)
Necessary method to avoid errors when trying to save unserializable objects.
def IsActive(self)
Method to specify when the toolbar button and the menu item are enabled.
def setProperties(self, vp)
Method to hide properties and select appropriate icon to show it the Tree View.