def __init__(self, layout: Layout): self.tsk = TaskManager() self.frame = layout.work_area self.font_size = 14 self.args_size = 15 self.entry = self.create_input(20, "Ingrese un comando", pos=0, command=execute) app.console_input = self.entry app.console = self self._args_input = dict() self._activecommand = None self._activearg = None
def create_bar(): global coredata # Agrega una tarea al TaskManager para dibujar la barra a crear print("create_bar") man = TaskManager() if not man.hasTaskNamed("create_bar"): man.add(bar_task, "create_bar") else: if coredata["line_node"] is not None: coredata["line_node"].removeNode() coredata["start"] = None coredata["end"] = None coredata["press"] = False coredata["line"] = None coredata["line_node"] = None coredata["last_node"] = None coredata["end_node"] = None del man
def __init__(self): DirectObject.__init__(self) self.filename = None self.unsaved = False self.idGenerator = IDGenerator() self.world = None self.isOpen = False self.gsg = None self.page = None self.shaderGenerator = None self.numlights = 0 # Each document has its own message bus, task manager, and event manager. self.taskMgr = TaskManager() self.taskMgr.mgr = AsyncTaskManager("documentTaskMgr") self.messenger = Messenger(self.taskMgr) self.eventMgr = EventManager(messenger=self.messenger, taskMgr=self.taskMgr) self.messenger.setEventMgr(self.eventMgr) self.render = NodePath("docRender") self.render.setAttrib(LightRampAttrib.makeIdentity()) #self.render.setShaderAuto() self.viewportMgr = ViewportManager(self) self.toolMgr = ToolManager(self) self.selectionMgr = SelectionManager(self) self.actionMgr = ActionManager(self) # Create the page that the document is viewed in. self.page = DocumentWindow(self) #self.createShaderGenerator() self.toolMgr.addTools() self.eventMgr.restart()
from direct.gui.DirectEntry import * from direct.task.Task import TaskManager from app.view.simpleui.simple_frame import SimpleFrame from app.view.widgets.gui_widget import GuiWidget from panda3d.core import MouseWatcher, PGEntry task_manager = TaskManager() mouse_watcher = MouseWatcher() from app import app import random from panda3d.core import TextProperties from app.view import draw from direct.gui import DirectGuiGlobals as DGG from app.view.simpleui import window class SimpleEntry(DirectEntry, SimpleFrame): def __init__(self, parent=None, **kw): # ('focusInCommand', self.on_focus, None), # ('focusOutCommand', self.on_defocus, None), optiondefs = ( # Define type of DirectGuiWidget ('label', "None", None), ('focusInExtraArgs', [], None), ('focusOutExtraArgs', [], None), ('textCenterX', True, self.update_text_pos), ('textCenterY', True, self.update_text_pos), ('align', "center", self.set_align), ('value', None, None), ('typeFunc', str, None),
class ConsoleUI(DirectObject): def __init__(self, layout: Layout): self.tsk = TaskManager() self.frame = layout.work_area self.font_size = 14 self.args_size = 15 self.entry = self.create_input(20, "Ingrese un comando", pos=0, command=execute) app.console_input = self.entry app.console = self self._args_input = dict() self._activecommand = None self._activearg = None @property def active_command(self): return self._activecommand @active_command.setter def active_command(self, value): if value is None: self.entry.show() for entry in self._args_input.values(): entry.detachNode() self._args_input.clear() elif self._activecommand is not value: self._activecommand = value data = app.commands.get(value, None) if data is not None: print("data", data) args = data.get("args") if args is not None: self.entry.hide() total_width = (self.args_size * self.font_size ) * len(args) + 40 * (len(args) - 1) x0 = -total_width / 2 print("x0", x0) for arg in args: x0 += self.args_size * self.font_size / 2 entry = self.create_input( self.args_size, arg, x0, command_focus=self.cmd_focus_in, command_defocus=self.cmd_focus_out, arg=arg) x0 += self.args_size * self.font_size / 2 + 40 self._args_input.update({arg: entry}) def cmd_focus_in(self, text, arg): self._activearg = arg def cmd_focus_out(self, text): self._activearg = None def get_active_arg(self): return self._activearg def get_arg(self, arg): entry = self._args_input.get(arg, None) if entry is not None: return entry.get_value() else: return None def set_arg(self, arg, value): entry = self._args_input.get(arg, None) if entry is not None: entry.enter_value(value) def set_arg_typefuc(self, arg, fuction): entry = self._args_input.get(arg, None) if entry is not None: entry["typeFunc"] = fuction def set_arg_suffix(self, arg, suffix): entry = self._args_input.get(arg, None) if entry is not None: entry["suffix"] = suffix def create_input(self, width, label, pos=0.0, command=None, command_focus=None, command_defocus=None, arg=None): entry = SimpleEntry(text_fg=(1, 1, 1, 1), orginH="center", orginV="bottom", position=[-width / 2 * self.font_size + pos, -25], text_scale=(self.font_size, self.font_size), width=width, frameColor="C_DKGRAY", label=label, align="center", command=command, parent=self.frame, focusInCommand=command_focus, focusInExtraArgs=[arg], focusOutCommand=command_defocus) app.add_gui_region("console_input", entry) entry.setColorScale(1, 1, 1, 1) # entry.setBin("fixed", 1) c = draw.draw_cicle(0, 9, 9, "C_DKGRAY", entry) c.setBin("fixed", 0) c = draw.draw_cicle(width * self.font_size, 9, 9, "C_DKGRAY", entry) c.setBin("fixed", 0) return entry def start_command(self, task): if not self.tsk.hasTaskNamed("command_task"): self.tsk.add(task, "command_task") def close_command(self): print("close_command start") if self.active_command: print("close_command", self.tsk.hasTaskNamed("command_task")) self.tsk.remove("command_task") self.active_command = None
def bar_task(task): # Establece coredata como variable global global coredata # Accede a la instancia base de la aplicación panda3d = app.get_show_base() watcher = panda3d.mouseWatcherNode box_input = app.console_input if coredata["start"] is not None and coredata["end"] is not None: # Una vez que se tiene un inicio y un fin creamos los nodos y la barra en el modelo x0, y0, z0 = coredata["start"] x1, y1, z1 = coredata["end"] if coredata["last_node"] is None: start_node = Node(x0, y0, z0) else: start_node = coredata["last_node"] if coredata["end_node"] is None: end_node = Node(x1, y1, z1) else: end_node = coredata["end_node"] section = Section(0.2, 0.3) Bar(start_node, end_node, section) coredata["last_node"] = end_node # Se crea una nueva linea para dibujar coredata["start"] = coredata["end"] coredata["line"].setVertex(0, x1, y1, z1) coredata["end"] = None #execute("regen") if app.mouse_on_workspace: if watcher.isButtonDown("mouse1"): if coredata["start"] is None and not coredata["press"]: # Almacena el valor de inicio del segmento de linea selection = app.main_ui.status_bar.entity_info if isinstance(selection, Node): coredata["start"] = selection.position coredata["last_node"] = selection else: coredata["start"] = app.work_plane_mouse coredata["press"] = True print("start") #print(coredata) create_line_seg(panda3d) elif coredata["end"] is None and not coredata["press"]: # Almacena el valor final del segmento de linea selection = app.main_ui.status_bar.entity_info if isinstance(selection, Node) and selection is not coredata["last_node"]: coredata["end"] = selection.position coredata["end_node"] = selection else: coredata["end"] = app.work_plane_mouse #coredata["end"] = app.work_plane_mouse coredata["press"] = True print("end") #print(coredata) else: if coredata["press"]: # Resetea una variable que permite detectar el momento en que se empieza a presionar el mouse coredata["press"] = False if coredata["start"] is not None and coredata["line"] is not None: # Actualiza la posición final de la línea a la ubicación del cursor, dejando fijo el origen line = coredata["line"] x0, y0, z0 = coredata["start"] x1, y1, z1 = app.work_plane_mouse bar_vect = np.array([x1 - x0, y1 - y0, z1 - z0]) bar_len = np.linalg.norm(bar_vect) if box_input["focus"] is True: print("focused") input_len = box_input.get() if input_len is not "": try: input_len = float(input_len) except Exception as ex: input_len = 0 else: input_len = 0 if input_len is None: input_len = 0 if bar_len is 0: bar_len = 1 bar_vect = input_len * (bar_vect / bar_len) x1, y1, z1 = coredata["start"] + bar_vect else: # Mostrar la longitud de la barra en pantalla box_input.enterText("{}".format(round(bar_len, 2))) line.setVertex(1, x1, y1, z1) if watcher.has_mouse() and (watcher.isButtonDown("escape") or watcher.isButtonDown("mouse3")): # Detiene la creación de la linea y resetea las variables box_input.enterText("") coredata["start"] = None coredata["end"] = None coredata["press"] = False if coredata["line_node"] is not None: print(coredata["line_node"]) coredata["line_node"].removeNode() man = TaskManager() man.remove("create_bar") del man return task.cont
class Document(DirectObject): def __init__(self): DirectObject.__init__(self) self.filename = None self.unsaved = False self.idGenerator = IDGenerator() self.world = None self.isOpen = False self.gsg = None self.gsg2D = None self.shaderGenerators = [] self.numlights = 0 # Each document has its own message bus, task manager, and event manager. self.taskMgr = TaskManager() self.taskMgr.mgr = AsyncTaskManager("documentTaskMgr") self.messenger = Messenger(self.taskMgr) self.eventMgr = EventManager(messenger = self.messenger, taskMgr = self.taskMgr) self.messenger.setEventMgr(self.eventMgr) self.render = NodePath("docRender") self.render.setAttrib(LightRampAttrib.makeIdentity()) self.render.setShaderAuto() self.viewportMgr = ViewportManager(self) self.toolMgr = ToolManager(self) self.selectionMgr = SelectionManager(self) self.actionMgr = ActionManager(self) # Create the page that the document is viewed in. self.page = DocumentWindow(self) self.createShaderGenerator() self.toolMgr.addTools() self.eventMgr.restart() def step(self): #print("Stepping", self) self.taskMgr.step() # Called when the document's tab has been switched into. def activated(self): # Move document constructs into global space so we don't have to directly # reference the document for them. base.render = self.render base.viewportMgr = self.viewportMgr base.toolMgr = self.toolMgr base.selectionMgr = self.selectionMgr base.actionMgr = self.actionMgr builtins.render = self.render messenger.send('documentActivated', [self]) # Called when the document's tab has been switched out of. def deactivated(self): messenger.send('documentDeactivated', [self]) def getNextID(self): return self.idGenerator.getNextID() def reserveID(self, id): self.idGenerator.reserveID(id) def getNextFaceID(self): return self.idGenerator.getNextFaceID() def reserveFaceID(self, id): self.idGenerator.reserveFaceID(id) def save(self, filename = None): # if filename is not none, this is a save-as if not filename: filename = self.filename kv = CKeyValues() self.world.doWriteKeyValues(kv) kv.write(filename, 4) self.filename = filename self.unsaved = False base.actionMgr.documentSaved() self.updateTabText() def close(self): if not self.isOpen: return self.toolMgr.cleanup() self.toolMgr = None self.world.delete() self.world = None self.idGenerator.cleanup() self.idGenerator = None self.filename = None self.unsaved = None self.isOpen = None self.gsg = None self.gsg2D = None self.shaderGenerators = None self.viewportMgr.cleanup() self.viewportMgr = None self.actionMgr.cleanup() self.actionMgr = None self.selectionMgr.cleanup() self.selectionMgr = None self.eventMgr.shutdown() self.eventMgr = None self.messenger = None self.taskMgr.destroy() self.taskMgr = None self.render.removeNode() self.render = None self.page.cleanup() self.page = None def __newMap(self): self.unsaved = False self.idGenerator.reset() self.world = World(self.getNextID()) self.world.reparentTo(self.render) self.isOpen = True self.toolMgr.switchToSelectTool() self.updateTabText() def updateTabText(self): title = self.getMapTitle() self.page.setWindowTitle(title) base.setWindowSubTitle(title) def r_open(self, kv, parent = None): classDef = MapObjectFactory.MapObjectsByName.get(kv.getName()) if not classDef: return id = int(kv.getValue("id")) self.reserveID(id) obj = classDef(id) obj.readKeyValues(kv) obj.reparentTo(parent) if classDef is World: self.world = obj for i in range(kv.getNumChildren()): self.r_open(kv.getChild(i), obj) def getViewport(self, type): return self.page.docWidget.viewports[type] def createShaderGenerator(self): for gsg, vp in [(self.gsg, self.getViewport(VIEWPORT_3D)), (self.gsg2D, self.getViewport(VIEWPORT_2D_FRONT))]: shgen = BSPShaderGenerator(vp.win, gsg, vp.camera, self.render) gsg.setShaderGenerator(shgen) for shader in ShaderGlobals.getShaders(): shgen.addShader(shader) self.shaderGenerators.append(shgen) def open(self, filename = None): # if filename is none, this is a new document/map if not filename: self.__newMap() return # opening a map from disk, read through the keyvalues and # generate the objects self.idGenerator.reset() root = CKeyValues.load(filename) for i in range(root.getNumChildren()): self.r_open(root.getChild(i)) self.unsaved = False self.filename = filename self.isOpen = True self.toolMgr.switchToSelectTool() self.updateTabText() def markSaved(self): self.unsaved = False self.updateTabText() def markUnsaved(self): self.unsaved = True self.updateTabText() def isUnsaved(self): return self.unsaved def getMapName(self): if not self.filename: return "Untitled" return self.filename.getBasename() def getMapTitle(self): name = self.getMapName() if self.unsaved: name += " *" return name def updateAllViews(self, now = False): for vp in self.viewportMgr.viewports: vp.updateView(now) def update2DViews(self, now = False): for vp in self.viewportMgr.viewports: if vp.is2D(): vp.updateView(now) def update3DViews(self, now = False): for vp in self.viewportMgr.viewports: if vp.is3D(): vp.updateView(now)