chiark / gitweb /
Merge pull request #601 from CapnBry/reloadscene
[cura.git] / Cura / util / printerConnection / printerConnectionBase.py
1 """
2 Base of all printer connections. A printer connection is a way a connection can be made with a printer.
3 The connections are based on a group, where each group can have 1 or more connections.
4 """
5 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
6
7 import traceback
8
9 class printerConnectionGroup(object):
10         """
11         Base for the printer connection group, needs to be subclassed.
12         Has functions for all available connections, getting the name, icon and priority.
13
14         The getIconID, getPriority and getAvailableConnections functions should be overloaded in a subclass.
15         """
16         def __init__(self, name):
17                 self._name = name
18
19         def getAvailableConnections(self):
20                 return []
21
22         def getName(self):
23                 return self._name
24
25         def getIconID(self):
26                 return 5
27
28         def getPriority(self):
29                 return -100
30
31         def __cmp__(self, other):
32                 return self.getPriority() - other.getPriority()
33
34         def __repr__(self):
35                 return '%s %d' % (self._name, self.getPriority())
36
37 class printerConnectionBase(object):
38         """
39         Base class for different printer connection implementations.
40                 A printer connection can connect to printers in different ways, trough network, USB or carrier pigeons.
41                 Each printer connection has different capabilities that you can query with the "has" functions.
42                 Each printer connection has a state that you can query with the "is" functions.
43                 Each printer connection has callback objects that receive status updates from the printer when information changes.
44         """
45         def __init__(self, name):
46                 self._callbackList = []
47                 self._name = name
48                 self.window = None
49
50         def getName(self):
51                 return self._name
52
53         #Load the data into memory for printing, returns True on success
54         def loadGCodeData(self, dataStream):
55                 return False
56
57         #Start printing the previously loaded file
58         def startPrint(self):
59                 pass
60
61         #Abort the previously loaded print file
62         def cancelPrint(self):
63                 pass
64
65         def isPrinting(self):
66                 return False
67
68         #Amount of progression of the current print file. 0.0 to 1.0
69         def getPrintProgress(self):
70                 return 0.0
71
72         #Returns true if we need to establish an active connection.
73         # Depending on the type of the connection some types do not need an active connection (Doodle3D WiFi Box for example)
74         def hasActiveConnection(self):
75                 return False
76
77         #Open the active connection to the printer so we can send commands
78         def openActiveConnection(self):
79                 pass
80
81         #Close the active connection to the printer
82         def closeActiveConnection(self):
83                 pass
84
85         #Is the active connection open right now.
86         def isActiveConnectionOpen(self):
87                 return False
88
89         #Are we trying to open an active connection right now.
90         def isActiveConnectionOpening(self):
91                 return False
92
93         #Returns true if we have the ability to pause the file printing.
94         def hasPause(self):
95                 return False
96
97         def isPaused(self):
98                 return False
99
100         #Pause or unpause the printing depending on the value, if supported.
101         def pause(self, value):
102                 pass
103
104         #Are we able to send a direct coammand with sendCommand at this moment in time.
105         def isAbleToSendDirectCommand(self):
106                 return False
107
108         #Directly send a command to the printer.
109         def sendCommand(self, command):
110                 pass
111
112         # Return if the printer with this connection type is available for possible printing right now.
113         #  It is used to auto-detect which connection should default to the print button.
114         #  This means the printer is detected, but no connection has been made yet.
115         #  Example: COM port is detected, but no connection has been made.
116         #  Example: WiFi box is detected and is ready to print with a printer connected
117         def isAvailable(self):
118                 return False
119
120         #Get the temperature of an extruder, returns None is no temperature is known for this extruder
121         def getTemperature(self, extruder):
122                 return None
123
124         #Get the temperature of the heated bed, returns None is no temperature is known for the heated bed
125         def getBedTemperature(self):
126                 return None
127
128         # Get the connection status string. This is displayed to the user and can be used to communicate
129         #  various information to the user.
130         def getStatusString(self):
131                 return "TODO"
132
133         def addCallback(self, callback):
134                 self._callbackList.append(callback)
135
136         def removeCallback(self, callback):
137                 if callback in self._callbackList:
138                         self._callbackList.remove(callback)
139
140         #Returns true if we got some kind of error. The getErrorLog returns all the information to diagnose the problem.
141         def isInErrorState(self):
142                 return False
143         #Returns the error log in case there was an error.
144         def getErrorLog(self):
145                 return ""
146
147         #Run a callback, this can be ran from a different thread, the receivers of the callback need to make sure they are thread safe.
148         def _doCallback(self, param=None):
149                 for callback in self._callbackList:
150                         try:
151                                 callback(self, param)
152                         except:
153                                 self.removeCallback(callback)
154                                 traceback.print_exc()