Exemple #1
0
class RotateObjectMouse(RotateObjectBase, RotateMouseMixin):
    description = "Rotate object"
    interactive_info = InteractiveInfo("plugins/basic/rotate.svg",
                                       mouse=True,
                                       order=0)
    authors = [authors.toon_verstraelen]

    def button_motion(self, drawing_area, event, start_button):
        self.do_rotation(*RotateMouseMixin.button_motion(
            self, drawing_area, event, start_button))
Exemple #2
0
class TranslateWorldMouse(TranslateWorldBase, TranslateMouseMixin):
    description = "Translate world"
    interactive_info = InteractiveInfo("plugins/basic/translate.svg",
                                       mouse=True,
                                       order=1)
    authors = [authors.toon_verstraelen]

    def button_motion(self, drawing_area, event, start_button):
        self.do_translation(
            TranslateMouseMixin.button_motion(self, drawing_area, event,
                                              start_button), drawing_area)
Exemple #3
0
class RotateObjectKeyboard(RotateObjectBase, RotateKeyboardMixin):
    description = "Rotate object"
    interactive_info = InteractiveInfo("plugins/basic/rotate.svg",
                                       keyboard=True,
                                       order=0)
    authors = [authors.toon_verstraelen]
    sensitive_keys = [65365, 65366, 65363, 65361, 65364, 65362]

    def key_press(self, drawing_area, event):
        self.do_rotation(
            *RotateKeyboardMixin.key_press(self, drawing_area, event))
Exemple #4
0
class TranslateViewerMouse(TranslateViewerBase, TranslateMouseMixin):
    description = "Translate the viewer position"
    interactive_info = InteractiveInfo("plugins/basic/translate_viewer.svg",
                                       mouse=True,
                                       order=0)
    authors = [authors.toon_verstraelen]

    def button_motion(self, drawing_area, event, start_button):
        self.do_translation(
            TranslateMouseMixin.button_motion(self, drawing_area, event,
                                              start_button), drawing_area)
Exemple #5
0
class PickSelection(Interactive):
    description = "Pick a selection"
    interactive_info = InteractiveInfo("plugins/basic/selection_picker.svg", mouse=True)
    authors = [authors.toon_verstraelen]

    def button_press(self, drawing_area, event):
        self.beginx = event.x
        self.beginy = event.y
        self.endx = event.x
        self.endy = event.y
        if event.button == 1 and event.type == gtk.gdk._2BUTTON_PRESS:
            nearest = context.application.main.drawing_area.get_nearest(event.x, event.y)
            if nearest is not None:
                context.application.action_manager.default_action(nearest)

    def button_motion(self, drawing_area, event, startbutton):
        self.endx = event.x
        self.endy = event.y
        r1 = drawing_area.screen_to_camera(numpy.array([self.beginx, self.beginy], float))
        r2 = drawing_area.screen_to_camera(numpy.array([event.x, event.y], float))
        context.application.vis_backend.tool("rectangle", r1, r2)

    def button_release(self, drawing_area, event):
        context.application.vis_backend.tool("clear")
        main = context.application.main
        if (event.button == 1):
            main.tree_selection.unselect_all()
        if abs(self.beginx - self.endx) > 1 or abs(self.beginy - self.endy) > 1:
            if self.beginx < self.endx:
                left = self.beginx
                right = self.endx
            else:
                left = self.endx
                right = self.beginx

            if self.beginy < self.endy:
                top = self.beginy
                bottom = self.endy
            else:
                top = self.endy
                bottom = self.beginy

            for hit in drawing_area.iter_hits((left, top, right, bottom)):
                main.toggle_selection(hit, event.button!=3)

        else:
            hit = drawing_area.get_nearest(event.x, event.y)
            if hit is None:
                main.tree_selection.unselect_all()
            else:
                main.toggle_selection(hit, event.button != 3)

        self.finish()
Exemple #6
0
class TranslateViewerKeyboard(TranslateViewerBase, TranslateKeyboardMixin):
    description = "Translate the viewer position"
    interactive_info = InteractiveInfo("plugins/basic/translate_viewer.svg",
                                       keyboard=True,
                                       order=0)
    authors = [authors.toon_verstraelen]
    sensitive_keys = [65365, 65366, 65363, 65361, 65364, 65362]

    def key_press(self, drawing_area, event):
        self.do_translation(
            TranslateKeyboardMixin.key_press(self, drawing_area, event),
            drawing_area)
Exemple #7
0
class Measure(Interactive):
    description = "Measure distances and angles"
    interactive_info = InteractiveInfo("plugins/basic/measure.svg", mouse=True)
    authors = [authors.toon_verstraelen]

    measurements = MeasurementsWindow()

    def button_press(self, drawing_area, event):
        if event.button == 1:
            gl_object = drawing_area.get_nearest(event.x, event.y)
            if isinstance(gl_object, GLTransformationMixin) and \
               isinstance(gl_object.transformation, Translation):
                self.measurements.add_object(gl_object)
                self.finish()
                return
            elif isinstance(gl_object, Vector):
                first = gl_object.children[0].target
                last = gl_object.children[1].target
                if len(self.measurements.model_objects) > 0:
                    if (first == self.measurements.model_objects[0] or \
                        last  == self.measurements.model_objects[0]) and \
                       (first != self.measurements.model_objects[-1] or \
                        last  != self.measurements.model_objects[-1]):
                        self.measurements.reverse()
                self.measurements.add_object(first)
                self.measurements.add_object(last)
                self.finish()
                return
        elif event.button == 2:
            self.measurements.reverse()
            self.finish()
            return
        elif event.button == 3:
            self.measurements.remove_last_object()
            self.finish()
            return
        self.measurements.clear()
        self.finish()
Exemple #8
0
class Sketch(Interactive):
    description = "Sketch objects and connectors"
    interactive_info = InteractiveInfo("plugins/molecular/sketch.svg",
                                       mouse=True)
    authors = [authors.toon_verstraelen]

    options = SketchOptions()

    def hit_criterion(self, gl_object):
        return (isinstance(gl_object, GLTransformationMixin)
                and isinstance(gl_object.transformation, Translation))

    def button_press(self, drawing_area, event):
        camera = context.application.camera
        self.first_hit = drawing_area.get_nearest(event.x, event.y)
        if not self.hit_criterion(self.first_hit):
            self.first_hit = None

        if self.first_hit is not None:
            tmp = camera.object_to_camera(self.first_hit)
            self.begin = drawing_area.camera_to_screen(tmp).astype(float)
            self.parent = self.first_hit.parent
        else:
            self.begin = numpy.array([event.x, event.y], float)
            node = context.application.cache.node
            if isinstance(node, GLContainerMixin):
                self.parent = node
            elif isinstance(node, ModelObject) and isinstance(
                    node.parent, GLContainerMixin):
                self.parent = node.parent
            else:
                self.parent = None

        if self.parent is None:
            self.parent = context.application.model.universe
        if self.first_hit is None:
            self.origin = self.parent.get_absolute_frame().t
        else:
            self.origin = self.first_hit.get_absolute_frame().t
        self.end = numpy.array([event.x, event.y], float)

        if event.button == 1:
            self.first_added = (self.first_hit is None)
            if self.first_added:
                self.first_hit = self.options.add_new(
                    self.parent.get_absolute_frame().inv *
                    camera.vector_in_plane(
                        drawing_area.screen_to_camera(
                            numpy.array([event.x, event.y], float)),
                        self.origin,
                    ), self.parent)
            self.tool = self.options.tool_draw
        elif event.button == 2 and self.first_hit is not None:
            self.tool = self.options.tool_special
            # a special modification of the selected object is going to happen
        elif event.button == 3:
            self.tool = self.options.erase_at
            self.tool(numpy.array([event.x, event.y], float), self.parent)
        else:
            raise ValueError("Unrecognized event.button = %s" % event.button)

        if self.tool is None or self.first_hit is None:
            self.finish()

    def button_motion(self, drawing_area, event, start_button):
        if self.tool == self.options.erase_at:
            self.tool(numpy.array([event.x, event.y], float), self.parent)
        else:
            self.end = numpy.array([event.x, event.y], float)
            self.tool(self.begin, self.end)

    def button_release(self, drawing_area, event):
        camera = context.application.camera
        context.application.vis_backend.tool("clear")
        self.end = numpy.array([event.x, event.y], float)

        if self.tool == self.options.erase_at:
            self.tool(numpy.array([event.x, event.y], float), self.parent)
            self.finish()
            return

        self.last_hit = drawing_area.get_nearest(event.x, event.y)
        if not self.hit_criterion(self.last_hit):
            self.last_hit = None
        moved = ((abs(self.begin - self.end) > 2).any()) and (
            ((self.first_hit is None) and
             (self.last_hit is None)) or (self.first_hit != self.last_hit))

        if moved:
            if self.tool == self.options.tool_draw:
                if self.last_hit is None:
                    self.last_hit = self.options.add_new(
                        self.parent.get_absolute_frame().inv *
                        camera.vector_in_plane(
                            drawing_area.screen_to_camera(
                                numpy.array([event.x, event.y], float)),
                            self.origin), self.parent)
                self.options.connect(self.first_hit, self.last_hit)
            elif self.tool == self.options.tool_special:
                self.options.move_special(self.first_hit, self.last_hit,
                                          self.begin, self.end)
        else:
            if self.tool == self.options.tool_draw and not self.first_added:
                self.options.replace(self.first_hit)
            elif self.tool == self.options.tool_special:
                self.options.click_special(self.first_hit)

        self.finish()