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),
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