def run(self): global filepath gl.log("running MagicDrawAnimator2") mode = 0 if mode == 0: #filepath = "c:\\Users\\bclement\\git\\bae\\simulationSnapshot.Scenario_medium_2012.txt" #filepath = "c:\\Users\\bclement\\Desktop\\large6.txt" #filepath = "c:\\Users\\bclement\\Desktop\\foo12.txt" #filepath = "/Users/mjackson/Desktop/testSim.txt" gl.log("default filepath = %s" % filepath) filepath = JOptionPane.showInputDialog( None, "Select File to Animate", "Select File", JOptionPane.PLAIN_MESSAGE, None, None, filepath) gl.log("reading events from " + filepath) self.events = [] try: f = open(filepath,"r") except: gl.log("can't find file @ %s" % filepath) return lastTime = float(0.0) latestTime = float(-1.0e20) earliestTime = float(1.0e20) gl.log( "MagicDrawAnimator2: before simulation, loading events from " + str(filepath) ) print( "MagicDrawAnimator2: before simulation, loading events from " + str(filepath) ) for line in f.readlines(): gl.log("read line = " + line) x = re.search("(\d*)[^0-9: \t\n\r\f\v]*\s*:\s*\S*\s*(\S*) -> (\S*)\s*(\S*) ==>",line) y = re.search("(\S*) -> (\S*)\s*(\S*) ==>",line) if x: eventTime=float(x.groups()[0]) lastTime = eventTime action=x.groups()[2] cid = x.groups()[3] ctype = x.groups()[1] #gl.log("%s %s (%s)" % (action.upper(), cid, ctype)) elif y: eventTime=lastTime action=y.groups()[1] cid = y.groups()[2] ctype = y.groups()[0] #gl.log("%s %s (%s)" % (action.upper(), cid, ctype)) elif line.startswith("---"): gl.log(line) continue else: continue #gl.log("%s %s (%s)" % (action.upper(), cid, ctype)) if any([x in cid for x in ["Main"]]): #gl.log(" ---> Skipping - can't animate Main") continue if re.search("(_)?Activity(_.*)?(?!\S)",ctype): #gl.log(" ---> Skipping - can't animate the Activity object!") continue try: if eventTime < earliestTime: earliestTime = eventTime if eventTime > latestTime: latestTime = eventTime evt = event(eventTime,action,cid,ctype) try: self.events.append(evt) except: gl.log("NESTED ARGHHHHH") except: gl.log("ARRGHHH") print( "MagicDrawAnimator2: finished loading events from " + str(filepath) ) gl.log( "MagicDrawAnimator2: finished loading events from " + str(filepath) ) elementsNotEnded = [] try: mda = MagicDrawAnimatorUtils2.MagicDrawAnimator2() #self.playEvents(mda) if self.timeScale == 0.0: gl.log("*** ZERO TIMESCALE: setting timeScale to 1.0") self.timeScale = 1.0 if usingDialogs: JOptionPane.showMessageDialog(self.frame,"Click ok to start simulation.") #simulatedDuration = (float(latestTime) - float(earliestTime))/ float(self.timeScale) simulatedDuration = (latestTime - earliestTime)/ self.timeScale lastTime = earliestTime elapsedTime = earliestTime simStartTime = earliestTime / self.timeScale #start at time of first event elapsedSimTime = simStartTime #start at time of first event zeroTime = time.time() except: exceptionType, exceptionValue, exceptionTraceback = sys.exc_info() gl.log("*** EXCEPTION:") messages=traceback.format_exception(exceptionType, exceptionValue, exceptionTraceback) for message in messages: gl.log(message) print("MagicDrawAnimator2: starting simulation with timeScale = " \ + str(self.timeScale) + "; last event at " + str(latestTime) \ + " scaling to " + str(simulatedDuration) + " seconds") gl.log("MagicDrawAnimator2: starting simulation with timeScale = " \ + str(self.timeScale) + "; last event at " + str(latestTime) \ + " scaling to " + str(simulatedDuration) + " seconds") try: for evt in self.events: #gl.log("EVENT at " + str(evt.eventTime)) #Sprint("EVENT at " + str(evt.eventTime)) try: timeOfNextEvent = (float(evt.eventTime) + 0.0) / self.timeScale except: exceptionType, exceptionValue, exceptionTraceback = sys.exc_info() gl.log("*** EXCEPTION:") messages=traceback.format_exception(exceptionType, exceptionValue, exceptionTraceback) for message in messages: gl.log(message) #print("1") if evt.eventTime != lastTime: mda.doThePaint() #paint all events occurring at the previous event time lastTime = float(evt.eventTime) #print("2") if timeOfNextEvent > elapsedSimTime: print("sleeping sim time of next event(" + str(timeOfNextEvent) \ + ") - elapsed sim time(" + str(elapsedSimTime) + ") = " \ + str(timeOfNextEvent - elapsedSimTime) + " seconds") gl.log("sleeping sim time of next event(" + str(timeOfNextEvent) \ + ") - elapsed sim time(" + str(elapsedSimTime) + ") = " \ + str(timeOfNextEvent - elapsedSimTime) + " seconds") if (timeOfNextEvent - elapsedSimTime) > 300: gl.log("found time jump > 300") break time.sleep( timeOfNextEvent - elapsedSimTime ) if "TimeVaryingMap" in evt.componentId: try: val = evt.action.split("=")[1] except: val = evt.action gl.log(" ---> (%s) SETTING VALUE of %s: %s" % (evt.eventTime,evt.componentType,val)) elif evt.componentType.startswith("sig") and "ObjectFlow" in evt.componentId: sid = evt.componentType.strip("sig") if "null" in evt.action and sid in elementsNotEnded: gl.log(" ---> (%s) ENDING SIGNAL %s" % (evt.eventTime,sid)) mda.end(sid) elementsNotEnded.remove(sid) elif "null" not in evt.action: gl.log(" ---> (%s) STARTING SIGNAL %s ==> %s" % (evt.eventTime,sid,evt.action)) txt = "" try: txt = evt.action.split("=")[1] except: txt = evt.action mda.start(sid,txt) if sid not in elementsNotEnded: elementsNotEnded.append(sid) elif "start" in evt.action: gl.log(" ---> (%s) STARTING" % evt.eventTime) mda.start(evt.componentId) if evt.componentId not in elementsNotEnded: elementsNotEnded.append(evt.componentId) elif "end" in evt.action: gl.log(" ---> (%s) ENDING" % evt.eventTime) mda.end(evt.componentId) if evt.componentId in elementsNotEnded: elementsNotEnded.remove(evt.componentId) t = time.time() elapsedSimTime = t - zeroTime + simStartTime elapsedTime = self.timeScale * elapsedSimTime gl.log("Debug: elapsed time = " + str(elapsedSimTime)) except: self.handleException() if len(elementsNotEnded)>0: gl.log("Ending Still-Active Events:") for e in elementsNotEnded: gl.log(" ending %s " % e) try: mda.end(e) except: self.handleException() mda.doThePaint() else: gl.log("All Events Completed") gl.log("DONE") elif mode == 1: e = "_17_0_2_edc0357_1352328158277_34448_20209" mda = MagicDrawAnimatorUtils2.MagicDrawAnimator2() gl.log("Starting e (%s)" % e) mda.start(e,"Porpoise Hork") mda.doThePaint() i = 3 while i > 0: i-=1 gl.log(".") time.sleep(1) gl.log("ending e") mda.end(e) mda.doThePaint() elif mode == 2: try: mda = MagicDrawAnimatorUtils2.MagicDrawAnimator2() e = "_17_0_2_edc0357_1352328158277_34448_20209" # in the usePower activity gl.log("Starting e (%s)" % e) mda.start(e) mda.doThePaint() tb = None pem = PresentationElementsManager.getInstance() sm = SessionManager.getInstance() try: sym = mda.gimmeTheSymbol(e) midPoint = sym.getMiddlePoint() sm.createSession("make box!") try: parentPM = sym.getPropertyManager() c = Color.GREEN tb = pem.createTextBox(sym,midPoint) newBounds = Rectangle(15,15) newBounds.setLocation(midPoint) pem.reshapeShapeElement(tb,newBounds) pem.setText(tb," gobblelkajdlfkjakj") pem.setPresentationElementProperties(tb, parentPM) sm.closeSession() except: sm.cancelSession() self.handleException() except: self.handleException() i = 3 while i > 0: i-=1 gl.log(".") time.sleep(1) gl.log("ending e") mda.end(e) if tb: sm.createSession("deleteBox!") try: pem.deletePresentationElement(tb) sm.closeSession() except: sm.cancelSession() self.handleException() mda.doThePaint() except: self.handleException()
def run(self): global filepath gl.log("running MagicDrawAnimator2") mode = 0 if mode == 0: #filepath = "c:\\Users\\bclement\\git\\bae\\simulationSnapshot.Scenario_medium_2012.txt" #filepath = "c:\\Users\\bclement\\Desktop\\large6.txt" #filepath = "c:\\Users\\bclement\\Desktop\\foo12.txt" #filepath = "/Users/mjackson/Desktop/testSim.txt" gl.log("default filepath = %s" % filepath) filepath = JOptionPane.showInputDialog(None, "Select File to Animate", "Select File", JOptionPane.PLAIN_MESSAGE, None, None, filepath) gl.log("reading events from " + filepath) self.events = [] try: f = open(filepath, "r") except: gl.log("can't find file @ %s" % filepath) return lastTime = float(0.0) latestTime = float(-1.0e20) earliestTime = float(1.0e20) gl.log( "MagicDrawAnimator2: before simulation, loading events from " + str(filepath)) print( "MagicDrawAnimator2: before simulation, loading events from " + str(filepath)) for line in f.readlines(): gl.log("read line = " + line) x = re.search( "(\d*)[^0-9: \t\n\r\f\v]*\s*:\s*\S*\s*(\S*) -> (\S*)\s*(\S*) ==>", line) y = re.search("(\S*) -> (\S*)\s*(\S*) ==>", line) if x: eventTime = float(x.groups()[0]) lastTime = eventTime action = x.groups()[2] cid = x.groups()[3] ctype = x.groups()[1] #gl.log("%s %s (%s)" % (action.upper(), cid, ctype)) elif y: eventTime = lastTime action = y.groups()[1] cid = y.groups()[2] ctype = y.groups()[0] #gl.log("%s %s (%s)" % (action.upper(), cid, ctype)) elif line.startswith("---"): gl.log(line) continue else: continue #gl.log("%s %s (%s)" % (action.upper(), cid, ctype)) if any([x in cid for x in ["Main"]]): #gl.log(" ---> Skipping - can't animate Main") continue if re.search("(_)?Activity(_.*)?(?!\S)", ctype): #gl.log(" ---> Skipping - can't animate the Activity object!") continue try: if eventTime < earliestTime: earliestTime = eventTime if eventTime > latestTime: latestTime = eventTime evt = event(eventTime, action, cid, ctype) try: self.events.append(evt) except: gl.log("NESTED ARGHHHHH") except: gl.log("ARRGHHH") print("MagicDrawAnimator2: finished loading events from " + str(filepath)) gl.log("MagicDrawAnimator2: finished loading events from " + str(filepath)) elementsNotEnded = [] try: mda = MagicDrawAnimatorUtils2.MagicDrawAnimator2() #self.playEvents(mda) if self.timeScale == 0.0: gl.log("*** ZERO TIMESCALE: setting timeScale to 1.0") self.timeScale = 1.0 if usingDialogs: JOptionPane.showMessageDialog( self.frame, "Click ok to start simulation.") #simulatedDuration = (float(latestTime) - float(earliestTime))/ float(self.timeScale) simulatedDuration = (latestTime - earliestTime) / self.timeScale lastTime = earliestTime elapsedTime = earliestTime simStartTime = earliestTime / self.timeScale #start at time of first event elapsedSimTime = simStartTime #start at time of first event zeroTime = time.time() except: exceptionType, exceptionValue, exceptionTraceback = sys.exc_info( ) gl.log("*** EXCEPTION:") messages = traceback.format_exception(exceptionType, exceptionValue, exceptionTraceback) for message in messages: gl.log(message) print("MagicDrawAnimator2: starting simulation with timeScale = " \ + str(self.timeScale) + "; last event at " + str(latestTime) \ + " scaling to " + str(simulatedDuration) + " seconds") gl.log("MagicDrawAnimator2: starting simulation with timeScale = " \ + str(self.timeScale) + "; last event at " + str(latestTime) \ + " scaling to " + str(simulatedDuration) + " seconds") try: for evt in self.events: #gl.log("EVENT at " + str(evt.eventTime)) #Sprint("EVENT at " + str(evt.eventTime)) try: timeOfNextEvent = (float(evt.eventTime) + 0.0) / self.timeScale except: exceptionType, exceptionValue, exceptionTraceback = sys.exc_info( ) gl.log("*** EXCEPTION:") messages = traceback.format_exception( exceptionType, exceptionValue, exceptionTraceback) for message in messages: gl.log(message) #print("1") if evt.eventTime != lastTime: mda.doThePaint( ) #paint all events occurring at the previous event time lastTime = float(evt.eventTime) #print("2") if timeOfNextEvent > elapsedSimTime: print("sleeping sim time of next event(" + str(timeOfNextEvent) \ + ") - elapsed sim time(" + str(elapsedSimTime) + ") = " \ + str(timeOfNextEvent - elapsedSimTime) + " seconds") gl.log("sleeping sim time of next event(" + str(timeOfNextEvent) \ + ") - elapsed sim time(" + str(elapsedSimTime) + ") = " \ + str(timeOfNextEvent - elapsedSimTime) + " seconds") if (timeOfNextEvent - elapsedSimTime) > 300: gl.log("found time jump > 300") break time.sleep(timeOfNextEvent - elapsedSimTime) if "TimeVaryingMap" in evt.componentId: try: val = evt.action.split("=")[1] except: val = evt.action gl.log(" ---> (%s) SETTING VALUE of %s: %s" % (evt.eventTime, evt.componentType, val)) elif evt.componentType.startswith( "sig") and "ObjectFlow" in evt.componentId: sid = evt.componentType.strip("sig") if "null" in evt.action and sid in elementsNotEnded: gl.log(" ---> (%s) ENDING SIGNAL %s" % (evt.eventTime, sid)) mda.end(sid) elementsNotEnded.remove(sid) elif "null" not in evt.action: gl.log(" ---> (%s) STARTING SIGNAL %s ==> %s" % (evt.eventTime, sid, evt.action)) txt = "" try: txt = evt.action.split("=")[1] except: txt = evt.action mda.start(sid, txt) if sid not in elementsNotEnded: elementsNotEnded.append(sid) elif "start" in evt.action: gl.log(" ---> (%s) STARTING" % evt.eventTime) mda.start(evt.componentId) if evt.componentId not in elementsNotEnded: elementsNotEnded.append(evt.componentId) elif "end" in evt.action: gl.log(" ---> (%s) ENDING" % evt.eventTime) mda.end(evt.componentId) if evt.componentId in elementsNotEnded: elementsNotEnded.remove(evt.componentId) t = time.time() elapsedSimTime = t - zeroTime + simStartTime elapsedTime = self.timeScale * elapsedSimTime gl.log("Debug: elapsed time = " + str(elapsedSimTime)) except: self.handleException() if len(elementsNotEnded) > 0: gl.log("Ending Still-Active Events:") for e in elementsNotEnded: gl.log(" ending %s " % e) try: mda.end(e) except: self.handleException() mda.doThePaint() else: gl.log("All Events Completed") gl.log("DONE") elif mode == 1: e = "_17_0_2_edc0357_1352328158277_34448_20209" mda = MagicDrawAnimatorUtils2.MagicDrawAnimator2() gl.log("Starting e (%s)" % e) mda.start(e, "Porpoise Hork") mda.doThePaint() i = 3 while i > 0: i -= 1 gl.log(".") time.sleep(1) gl.log("ending e") mda.end(e) mda.doThePaint() elif mode == 2: try: mda = MagicDrawAnimatorUtils2.MagicDrawAnimator2() e = "_17_0_2_edc0357_1352328158277_34448_20209" # in the usePower activity gl.log("Starting e (%s)" % e) mda.start(e) mda.doThePaint() tb = None pem = PresentationElementsManager.getInstance() sm = SessionManager.getInstance() try: sym = mda.gimmeTheSymbol(e) midPoint = sym.getMiddlePoint() sm.createSession("make box!") try: parentPM = sym.getPropertyManager() c = Color.GREEN tb = pem.createTextBox(sym, midPoint) newBounds = Rectangle(15, 15) newBounds.setLocation(midPoint) pem.reshapeShapeElement(tb, newBounds) pem.setText(tb, " gobblelkajdlfkjakj") pem.setPresentationElementProperties(tb, parentPM) sm.closeSession() except: sm.cancelSession() self.handleException() except: self.handleException() i = 3 while i > 0: i -= 1 gl.log(".") time.sleep(1) gl.log("ending e") mda.end(e) if tb: sm.createSession("deleteBox!") try: pem.deletePresentationElement(tb) sm.closeSession() except: sm.cancelSession() self.handleException() mda.doThePaint() except: self.handleException()
def diagrambuttonPressed(event) : IJ.showMessage("Push 'Auto' button each time you want to see the diagram") x1=10 y1=20 x2=100 y2=50 x3=60 y3=30 xr=10 yr=20 wr=20 hr=20 rect=Rectangle(xr,yr,wr,hr) #img=IJ.getImage() #nbslices=self.__img.getImageStackSize() nbslices=self.__maxLife IJ.run("Hyperstack...", "title=Diagram type=32-bit display=Color width="+str(x2+(nbslices+1)*x3)+" height="+str(y2+y3*len(dico))+" channels=1 slices="+str(len(self.__measures))+" frames=1") im=IJ.getImage() ip=im.getProcessor() for i in range(len(self.__measures)) : indiceligne=0 maxvalue=0 minvalue=1000000 im.setPosition(1,i+1,1) for cellname in self.__listcellname : indiceligne+=1 for indicecolonne in range(1,nbslices+1): rect.setLocation(x2+indicecolonne*x3+int(x3/6),(y1+indiceligne*y3-int(y3/2))) # we create at the first iteration a dictionary with the rectangles (for a future use) if i==0 : self.__gridrectangle[(indiceligne,indicecolonne)]=Rectangle(rect) im.setRoi(rect) ipr=im.getProcessor() # we find the min and max values of the datas for a measure given. if self.__dictMeasures[dico[cellname]][self.__measures[i]][indicecolonne-1]>maxvalue : maxvalue=self.__dictMeasures[dico[cellname]][self.__measures[i]][indicecolonne-1] if self.__dictMeasures[dico[cellname]][self.__measures[i]][indicecolonne-1]<minvalue : minvalue=self.__dictMeasures[dico[cellname]][self.__measures[i]][indicecolonne-1] # we fill the rectangle with the value of the measure ipr.setValue(self.__dictMeasures[dico[cellname]][self.__measures[i]][indicecolonne-1]) ipr.fill() # we write the names and the n of slices on the image with the maxvalue. ip.setValue(maxvalue) ip.moveTo(x1,y1) ip.drawString(self.__measures[i]) for j in range(1,nbslices+1) : ip.moveTo(x2+j*x3,y1) ip.drawString("Slice "+str(j)) j=0 for cellname in self.__listcellname : ip.moveTo(x1,y2+j*y3) ip.drawString(cellname) j+=1 im.killRoi() im=IJ.run(im,"Fire","") IJ.run("Brightness/Contrast...", "") #im.setMinAndMax(minvalue,maxvalue) #im.updateImage() #we add a mouse listener in order to be able to show the roi corresponding to a rectangle when the user clicks on it. listener = ML() listener.name=imgName for imp in map(WindowManager.getImage, WindowManager.getIDList()): if imp.getTitle().startswith("Diagram") : win = imp.getWindow() if win is None: continue win.getCanvas().addMouseListener(listener)