Ejemplo n.º 1
0
	def modal(self, context, event):
		if (event.type == 'ESC'):  # Cancel
			for objectLog, process in self.pendingProcesses.items():
				process.kill() 
				objectLog.mStatus = "(Canceling...)"
			self.canceling = True
			self.refresh(context)
			return {'RUNNING_MODAL'}

		if (LogManager.getLogCount() == 0):
			# add first item to log so we can see the progress.
			# TODO: Fix this for when no mesh data are exported but materials are.
			LogManager.addObjectLog(self.collection[0].name, ObjectLog.TYPE_MESH)
			LogManager.setProgress(0)
			self.refresh(context)
			return {'RUNNING_MODAL'}

		# poll subprocesses to make sure they are done and log accordingly.
		pendingDelete = list()
		for objectLog, process in self.pendingProcesses.items():
			result = process.poll()
			if (result == None): continue
			if (result == 0):
				objectLog.mStatus = ""
				objectLog.logMessage("OgreXMLConverter Success!")
				objectLog.mState = ObjectLog.ST_SUCCEED
				self.completedCount += 1
			elif (self.canceling):
				objectLog.mStatus = "(Canceled)"
				objectLog.logMessage("OgreXMLConverter Canceled.", Message.LVL_INFO)
				objectLog.mState = ObjectLog.ST_CANCELED
			else:
				objectLog.mStatus = ""
				objectLog.logMessage("OgreXMLConverter Failed! Check log file for more detail.", Message.LVL_ERROR)
				objectLog.mState = ObjectLog.ST_FAILED
			pendingDelete.append(objectLog) # cache it for delete.
		# delete from dictionary what needs to be deleted.
		# (Wish python has smarter way to do this -_-" Why can't they have erase iterator system?)
		for objectLog in pendingDelete: del self.pendingProcesses[objectLog]
		# check that we do not have too many process running. If so, skip until done.
		if (len(self.pendingProcesses) == OperatorExport.MAX_PENDING_PROCESSES):
			self.refresh(context)
			return {'RUNNING_MODAL'}

		# Check exit strategy.
		if (self.itemIndex == self.collectionCount or self.canceling):
			if (len(self.pendingProcesses)): return {'RUNNING_MODAL'}
			context.window_manager.event_timer_remove(self.timer)
			LogManager.setProgress(100)
			self.refresh(context)
			return {'FINISHED'}

		# TODO: Handle exportMeshes == FALSE state.
		item = self.collection[self.itemIndex]
		object = bpy.data.objects[item.objectName]
		#~ time.sleep(0.1)
		result = exportMesh(object, "%s%s.mesh.xml" % (self.globalSettings.exportPath, item.name))
		objectLog = LogManager.getObjectLog(-1)
		if (not result[0]): objectLog.mState = ObjectLog.ST_FAILED
		elif (result[1]):
			self.pendingProcesses[objectLog] = result[1]
			objectLog.mStatus = "(Converting...)"
			objectLog.mState = ObjectLog.ST_CONVERTING
		else:
			objectLog.mState = ObjectLog.ST_SUCCEED
			self.completedCount += 1

		# update progress bar.
		LogManager.setProgress((100 * self.completedCount) / self.collectionCount)

		self.itemIndex += 1
		if (self.itemIndex < self.collectionCount):
			LogManager.addObjectLog(self.collection[self.itemIndex].name, ObjectLog.TYPE_MESH)

		# tell blender to refresh.
		self.refresh(context)
		return {'RUNNING_MODAL'}
Ejemplo n.º 2
0
    def modal(self, context, event):
        if (event.type == 'ESC'):  # Cancel
            for objectLog, process in self.pendingProcesses.items():
                process.kill()
                objectLog.mStatus = "(Canceling...)"
            self.canceling = True
            self.refresh(context)
            return {'RUNNING_MODAL'}

        if (LogManager.getLogCount() == 0):
            # add first item to log so we can see the progress.
            # TODO: Fix this for when no mesh data are exported but materials are.
            LogManager.addObjectLog(self.collection[0].name,
                                    ObjectLog.TYPE_MESH)
            LogManager.setProgress(0)
            self.refresh(context)
            return {'RUNNING_MODAL'}

        # poll subprocesses to make sure they are done and log accordingly.
        pendingDelete = list()
        for objectLog, process in self.pendingProcesses.items():
            result = process.poll()
            if (result == None): continue
            if (result == 0):
                objectLog.mStatus = ""
                objectLog.logMessage("OgreXMLConverter Success!")
                objectLog.mState = ObjectLog.ST_SUCCEED
                self.completedCount += 1
            elif (self.canceling):
                objectLog.mStatus = "(Canceled)"
                objectLog.logMessage("OgreXMLConverter Canceled.",
                                     Message.LVL_INFO)
                objectLog.mState = ObjectLog.ST_CANCELED
            else:
                objectLog.mStatus = ""
                objectLog.logMessage(
                    "OgreXMLConverter Failed! Check log file for more detail.",
                    Message.LVL_ERROR)
                objectLog.mState = ObjectLog.ST_FAILED
            pendingDelete.append(objectLog)  # cache it for delete.
        # delete from dictionary what needs to be deleted.
        # (Wish python has smarter way to do this -_-" Why can't they have erase iterator system?)
        for objectLog in pendingDelete:
            del self.pendingProcesses[objectLog]
        # check that we do not have too many process running. If so, skip until done.
        if (len(self.pendingProcesses) == OperatorExport.MAX_PENDING_PROCESSES
            ):
            self.refresh(context)
            return {'RUNNING_MODAL'}

        # Check exit strategy.
        if (self.itemIndex == self.collectionCount or self.canceling):
            if (len(self.pendingProcesses)): return {'RUNNING_MODAL'}
            context.window_manager.event_timer_remove(self.timer)
            LogManager.setProgress(100)
            self.refresh(context)
            return {'FINISHED'}

        # TODO: Handle exportMeshes == FALSE state.
        item = self.collection[self.itemIndex]
        object = bpy.data.objects[item.objectName]
        #~ time.sleep(0.1)
        result = exportMesh(
            object,
            "%s%s.mesh.xml" % (self.globalSettings.exportPath, item.name))
        objectLog = LogManager.getObjectLog(-1)
        if (not result[0]): objectLog.mState = ObjectLog.ST_FAILED
        elif (result[1]):
            self.pendingProcesses[objectLog] = result[1]
            objectLog.mStatus = "(Converting...)"
            objectLog.mState = ObjectLog.ST_CONVERTING
        else:
            objectLog.mState = ObjectLog.ST_SUCCEED
            self.completedCount += 1

        # update progress bar.
        LogManager.setProgress(
            (100 * self.completedCount) / self.collectionCount)

        self.itemIndex += 1
        if (self.itemIndex < self.collectionCount):
            LogManager.addObjectLog(self.collection[self.itemIndex].name,
                                    ObjectLog.TYPE_MESH)

        # tell blender to refresh.
        self.refresh(context)
        return {'RUNNING_MODAL'}