Changeset 806
- Timestamp:
- Jan 28, 2005, 5:53:59 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pmesh/pmesh.py
r713 r806 17 17 TRIANGLE_COLOUR = 'green' 18 18 APPLICATION_NAME = 'Pmesh' 19 SET_COLOUR = 'red' 19 20 20 21 NO_SELECTION = 0 … … 199 200 statushelp='' ) 200 201 202 203 204 def createSetTools(self): 205 """ 206 Add set tool buttons to the top of the GUI 207 """ 208 ToolBarButton(self, self.toolbar, 'sep', 'sep.gif', width=10, 209 state='disabled') 210 for key, func, balloon in [ 211 ('threshold', self.threshold, 'threshold the set'), 212 ('Courant_threshold', self.Courant_threshold, 'Courant_threshold the set'), 213 ('polyset', self.triangles_to_polySet, 'make a poly set out of selected triangles'), 214 ('refineSet', self.refineSet, 'Refine the set')]: 215 ToolBarButton(self, self.toolbar, key, '%s.gif' %key, 216 command=func, balloonhelp=balloon, 217 statushelp='' ) 218 219 def createSetIcons(self): 220 """ 221 Add Edit buttons to the top of the GUI 222 """ 223 ToolBarButton(self, self.toolbar, 'sep', 'sep.gif', width=10, 224 state='disabled') 225 for key, func, balloon in [ 226 ('selectAllTriangles', self.selectAllTriangles, 'select all'), 227 ('none', self.clearSelection, 'clear selection')]: 228 ToolBarButton(self, self.toolbar, key, '%s.gif' %key, 229 command=func, balloonhelp=balloon, 230 statushelp='' ) 231 232 233 234 def refineSet(self,parent): 235 self.mesh.refineSet(self.selSet) 236 self.mesh.drawSet(self.canvas,self.selSet,self.SCALE,colour=SET_COLOUR) 237 238 def setStructureNumber(self,parent): 239 dialog = setStructureNumberDialog(self.canvas) 240 if dialog.numberOK: 241 self.structureSize = dialog.number 242 243 def erode(self, parent): 244 #Not implimented 245 self.mesh.undrawSet(self.canvas,self.selSet,self.SCALE) 246 self.mesh.erode(self.selSet,structureSize=self.structureSize) 247 self.mesh.drawSet(self.canvas,self.selSet,self.SCALE,colour=SET_COLOUR) 248 249 def dilate(self, parent): 250 #Not implimented 251 self.mesh.undrawSet(self.canvas,self.selSet,self.SCALE) 252 self.mesh.dilate(self.selSet,structureSize=self.structureSize) 253 self.mesh.drawSet(self.canvas,self.selSet,self.SCALE,colour=SET_COLOUR) 254 255 256 def threshold(self, parent): 257 """ 258 add a vertex using a window and entering x y values. 259 260 the parent attribute isn't used by this function. 261 need to userstand toolbarbutton.py to know how to 262 get rid of it. 263 """ 264 if self.selSet == 'None': 265 self.selectAllTriangles(parent) 266 267 dialog = ThresholdDialog(self.canvas) 268 if dialog.minmaxValuesOk: 269 self.mesh.undrawSet(self.canvas,self.selSet,self.SCALE) 270 self.mesh.threshold(self.selSet,min=dialog.min,max=dialog.max) 271 self.mesh.drawSet(self.canvas,self.selSet,self.SCALE,colour=SET_COLOUR) 272 273 def Courant_threshold(self, parent): 274 """ 275 add a vertex using a window and entering x y values. 276 277 the parent attribute isn't used by this function. 278 need to userstand toolbarbutton.py to know how to 279 get rid of it. 280 """ 281 if self.selSet == 'None': 282 self.selectAllTriangles(parent) 283 284 dialog = Courant_ThresholdDialog(self.canvas) 285 if dialog.minmaxValuesOk: 286 self.mesh.undrawSet(self.canvas,self.selSet,self.SCALE) 287 self.mesh.Courant_threshold(self.selSet,min=dialog.min,max=dialog.max) 288 self.mesh.drawSet(self.canvas,self.selSet,self.SCALE,colour=SET_COLOUR) 289 290 def triangles_to_polySet(self,parent): 291 vertices, segments = self.mesh.triangles_to_polySet(self.selSet) 292 event = None 293 for v in vertices.keys(): 294 x = v.x*self.SCALE 295 y = v.y*self.SCALE 296 vertices[v]=self.drawVertex(x,y,event) 297 for s in segments: 298 v0 = vertices[s[0]] 299 v1 = vertices[s[1]] 300 self.drawSegment(v0,v1) 301 302 def selectTriangles(self,setName): 303 """ 304 """ 305 self.mesh.undrawSet(self.canvas,self.selSet,self.SCALE) 306 self.selSet = setName 307 self.mesh.drawSet(self.canvas,self.selSet,self.SCALE,colour=SET_COLOUR) 308 309 def selectAllTriangles(self,parent): 310 """ 311 selected all triangles in the mesh 312 """ 313 self.selSet = self.mesh.selectAllTriangles() 314 self.mesh.drawSet(self.canvas,self.selSet,self.SCALE,colour=SET_COLOUR) 315 316 def clearSelection(self,parent): 317 """ 318 """ 319 self.mesh.undrawSet(self.canvas,self.selSet,self.SCALE) 320 self.selSet = self.mesh.clearSelection() 321 322 201 323 def createMesh(self): 202 324 """ … … 212 334 213 335 self.Triangles = visualmesh.vTriangles(mesh.Triangle) 336 self.selSet='None' 214 337 215 338 … … 1081 1204 def close(self): 1082 1205 self.quit() 1083 1084 1206 def createInterface(self): 1085 1207 """ … … 1095 1217 self.createZooms() 1096 1218 self.createEdits() 1219 self.createSetTools() 1220 self.createSetIcons() 1097 1221 #self.addVertsAndSegs() # !!!DSG start pmesh with a triangle 1098 1222 self.selectFunc('pointer') … … 1321 1445 showerror('Bad mesh generation values', 1322 1446 'Values are out of range.') 1447 1448 1449 class ThresholdDialog(Dialog): 1450 """ 1451 Dialog box for thresholding a set by entering minimum 1452 and maximum values 1453 """ 1454 def body(self, master): 1455 """ 1456 GUI description 1457 """ 1458 self.title("Threshold selected set") 1459 1460 Label(master, text='minimum attribute:').grid(row=0, sticky=W) 1461 Label(master, text='maximum attribute:').grid(row=1, sticky=W) 1462 1463 self.minstr = Entry(master, width = 16, name ="entry") 1464 self.maxstr = Entry(master, width = 16) 1465 1466 self.minstr.grid(row=0, column=1, sticky=W) 1467 self.maxstr.grid(row=1, column=1, sticky=W) 1468 self.minstr.focus_force() 1469 self.min = 0 1470 self.max = 0 1471 self.minmaxValuesOk = False 1472 1473 def apply(self): 1474 self.minmaxValuesOk = True 1475 try: 1476 self.min = float(self.minstr.get()) 1477 self.max = float(self.maxstr.get()) 1478 except ValueError: 1479 self.ValuesOk = False 1480 showerror('Bad mesh generation values', 1481 ' Values are not numbers.') 1482 1483 1484 class Courant_ThresholdDialog(Dialog): 1485 """ 1486 Dialog box for Courant_thresholding a set by entering minimum 1487 and maximum values 1488 """ 1489 def body(self, master): 1490 """ 1491 GUI description 1492 """ 1493 self.title("Courant_Threshold selected set") 1494 1495 Label(master, text='minimum attribute:').grid(row=0, sticky=W) 1496 Label(master, text='maximum attribute:').grid(row=1, sticky=W) 1497 1498 self.minstr = Entry(master, width = 16, name ="entry") 1499 self.maxstr = Entry(master, width = 16) 1500 1501 self.minstr.grid(row=0, column=1, sticky=W) 1502 self.maxstr.grid(row=1, column=1, sticky=W) 1503 self.minstr.focus_force() 1504 self.min = 0 1505 self.max = 0 1506 self.minmaxValuesOk = False 1507 1508 def apply(self): 1509 self.minmaxValuesOk = True 1510 try: 1511 self.min = float(self.minstr.get()) 1512 self.max = float(self.maxstr.get()) 1513 except ValueError: 1514 self.ValuesOk = False 1515 showerror('Bad mesh generation values', 1516 ' Values are not numbers.') 1517 1518 1519 class setStructureNumberDialog(Dialog): 1520 """ 1521 Dialog box for setting the number of triangles 1522 used to make up dilation or erosion 1523 """ 1524 def body(self, master): 1525 """ 1526 GUI description 1527 """ 1528 self.title("Set number of elements effected by morphing sets") 1529 1530 Label(master, text='number:').grid(row=0, sticky=W) 1531 1532 self.number = Entry(master, width = 16, name ="entry") 1533 1534 self.number.grid(row=0, column=1, sticky=W) 1535 self.number.focus_force() 1536 self.number = 0 1537 self.numberOk = False 1538 1539 def apply(self): 1540 self.numberOk = True 1541 try: 1542 self.number = int(self.number.get()) 1543 except ValueError: 1544 self.numberOK = False 1545 showerror('Bad mesh generation values', 1546 ' Values are not numbers.') 1547 1548 1323 1549 1324 1550 if __name__ == '__main__':
Note: See TracChangeset
for help on using the changeset viewer.