Пример #1
0
 def invoke(self, context, event):
     e = context.object
     locEnd = cursor_2d_to_location_3d(context, event)
     # try to get a wall instance assuming <e> is a corner EMPTY located at either free end of the wall
     wall = getWallFromEmpty(context, self, e, True)
     if wall:
         o = wall.extend(e, locEnd)
         bpy.ops.object.select_all(action="DESELECT")
         self.mover = AlongSegmentMover(wall, o)
         # set mode of operation
         self.attached = False
     else:
         # try to get a wall instance assuming <empty> is a segment EMPTY
         if e and "t" in e and e["t"] == "ws":
             wall = getWallFromEmpty(context, self, e, False)
             if wall:
                 # wall.startAttachedWall(empty, locEnd) returns segment EMPTY
                 o = wall.startAttachedWall(e, locEnd)
                 bpy.ops.object.select_all(action="DESELECT")
                 self.mover = SegmentMover(getWallFromEmpty(context, self, o), o)
                 # set mode of operation
                 self.attached = True
         if not wall:
             self.report({"ERROR"}, "To extend the wall, select an EMPTY object at either free end of the wall")
             return {"CANCELLED"}
     self.state = self.set_location
     self.lastOperator = getLastOperator(context)
     # The order how self.mover.start() and context.window_manager.modal_handler_add(self)
     # are called is important. If they are called in the reversed order, it won't be possible to
     # capture X, Y, Z keys
     self.mover.start()
     context.window_manager.modal_handler_add(self)
     return {"RUNNING_MODAL"}
Пример #2
0
    def connectSegments(self, context, wall1, wall2, o1, o2):
        o = wall1.connect(wall2, o1, o2)

        bpy.ops.object.select_all(action="DESELECT")

        self.lastOperator = getLastOperator(context)
        mover = SegmentMover(getWallFromEmpty(context, self, o), o)
        self.mover = mover
        self.finished = False
        # The order how self.mover.start() and context.window_manager.modal_handler_add(self)
        # are called is important. If they are called in the reversed order, it won't be possible to
        # capture X, Y, Z keys
        mover.start()
        context.window_manager.modal_handler_add(self)
        return {'RUNNING_MODAL'}
Пример #3
0
    def connectSegments(self, context, wall1, wall2, o1, o2):
        o = wall1.connect(wall2, o1, o2)

        bpy.ops.object.select_all(action="DESELECT")

        self.lastOperator = getLastOperator(context)
        mover = SegmentMover(getWallFromEmpty(context, self, o), o)
        self.mover = mover
        self.finished = False
        # The order how self.mover.start() and context.window_manager.modal_handler_add(self)
        # are called is important. If they are called in the reversed order, it won't be possible to
        # capture X, Y, Z keys
        mover.start()
        context.window_manager.modal_handler_add(self)
        return {"RUNNING_MODAL"}
Пример #4
0
 def invoke(self, context, event):
     e = context.object
     locEnd = cursor_2d_to_location_3d(context, event)
     # try to get a wall instance assuming <e> is a corner EMPTY located at either free end of the wall
     wall = getWallFromEmpty(context, self, e, True)
     if wall:
         o = wall.extend(e, locEnd)
         bpy.ops.object.select_all(action="DESELECT")
         self.mover = AlongSegmentMover(wall, o)
         # set mode of operation
         self.attached = False
     else:
         # try to get a wall instance assuming <empty> is a segment EMPTY
         if e and "t" in e and e["t"] == "ws":
             wall = getWallFromEmpty(context, self, e, False)
             if wall:
                 # wall.startAttachedWall(empty, locEnd) returns segment EMPTY
                 o = wall.startAttachedWall(e, locEnd)
                 bpy.ops.object.select_all(action="DESELECT")
                 self.mover = SegmentMover(
                     getWallFromEmpty(context, self, o), o)
                 # set mode of operation
                 self.attached = True
         if not wall:
             self.report({
                 'ERROR'
             }, "To extend the wall, select an EMPTY object at either free end of the wall"
                         )
             return {'CANCELLED'}
     self.state = self.set_location
     self.lastOperator = getLastOperator(context)
     # The order how self.mover.start() and context.window_manager.modal_handler_add(self)
     # are called is important. If they are called in the reversed order, it won't be possible to
     # capture X, Y, Z keys
     self.mover.start()
     context.window_manager.modal_handler_add(self)
     return {'RUNNING_MODAL'}
Пример #5
0
class WallEditExtend(bpy.types.Operator):
    bl_idname = "prk.wall_edit_extend"
    bl_label = "Extend the wall or start an attached wall"
    bl_description = "Extend the wall or start a wall attached to the selected wall segment"
    bl_options = {"REGISTER", "UNDO"}

    # states
    set_location = (1, )
    set_location_finished = (1, )
    set_length = (1, )
    finished = (1, )

    length = bpy.props.FloatProperty(
        name="Length",
        description="The length of the wall segment",
        default=2,
        min=0.1,
        max=100,
        unit="LENGTH")

    def modal(self, context, event):
        state = self.state
        mover = self.mover

        if state is self.set_location:
            # capture X, Y, Z keys for attached walls
            if self.attached and event.type in {'X', 'Y', 'Z'}:
                return {'RUNNING_MODAL'}
            operator = getLastOperator(context)
            if operator != self.lastOperator or event.type in {
                    'RIGHTMOUSE', 'ESC'
            }:
                # let cancel event happen, i.e. don't call op.mover.end() immediately
                self.state = self.set_location_finished if self.attached else self.finished
                self.lastOperator = operator
        elif state is self.set_location_finished:
            # this state is for attached walls only!
            mover.end()
            mover.o.select = False
            self.state = self.set_length
            # starting AlongLineMover
            mover = AlongSegmentMover(mover.wall, mover.o2)
            self.mover = mover
            mover.start()
        elif state is self.set_length:
            # this state is for attached walls only!
            operator = getLastOperator(context)
            # The condition operator != self.lastOperator means,
            # that the modal operator started by mover.start() finished its work
            if operator != self.lastOperator or event.type in {
                    'RIGHTMOUSE', 'ESC'
            }:
                # let cancel event happen, i.e. don't call mover.end() immediately
                self.state = self.finished
        elif state is self.finished:
            mover.end()
            return {'FINISHED'}
        return {'PASS_THROUGH'}

    def invoke(self, context, event):
        e = context.object
        locEnd = cursor_2d_to_location_3d(context, event)
        # try to get a wall instance assuming <e> is a corner EMPTY located at either free end of the wall
        wall = getWallFromEmpty(context, self, e, True)
        if wall:
            o = wall.extend(e, locEnd)
            bpy.ops.object.select_all(action="DESELECT")
            self.mover = AlongSegmentMover(wall, o)
            # set mode of operation
            self.attached = False
        else:
            # try to get a wall instance assuming <empty> is a segment EMPTY
            if e and "t" in e and e["t"] == "ws":
                wall = getWallFromEmpty(context, self, e, False)
                if wall:
                    # wall.startAttachedWall(empty, locEnd) returns segment EMPTY
                    o = wall.startAttachedWall(e, locEnd)
                    bpy.ops.object.select_all(action="DESELECT")
                    self.mover = SegmentMover(
                        getWallFromEmpty(context, self, o), o)
                    # set mode of operation
                    self.attached = True
            if not wall:
                self.report({
                    'ERROR'
                }, "To extend the wall, select an EMPTY object at either free end of the wall"
                            )
                return {'CANCELLED'}
        self.state = self.set_location
        self.lastOperator = getLastOperator(context)
        # The order how self.mover.start() and context.window_manager.modal_handler_add(self)
        # are called is important. If they are called in the reversed order, it won't be possible to
        # capture X, Y, Z keys
        self.mover.start()
        context.window_manager.modal_handler_add(self)
        return {'RUNNING_MODAL'}
Пример #6
0
class WallEditExtend(bpy.types.Operator):
    bl_idname = "prk.wall_edit_extend"
    bl_label = "Extend the wall or start an attached wall"
    bl_description = "Extend the wall or start a wall attached to the selected wall segment"
    bl_options = {"REGISTER", "UNDO"}

    # states
    set_location = (1,)
    set_location_finished = (1,)
    set_length = (1,)
    finished = (1,)

    length = bpy.props.FloatProperty(
        name="Length", description="The length of the wall segment", default=2, min=0.1, max=100, unit="LENGTH"
    )

    def modal(self, context, event):
        state = self.state
        mover = self.mover

        if state is self.set_location:
            # capture X, Y, Z keys for attached walls
            if self.attached and event.type in {"X", "Y", "Z"}:
                return {"RUNNING_MODAL"}
            operator = getLastOperator(context)
            if operator != self.lastOperator or event.type in {"RIGHTMOUSE", "ESC"}:
                # let cancel event happen, i.e. don't call op.mover.end() immediately
                self.state = self.set_location_finished if self.attached else self.finished
                self.lastOperator = operator
        elif state is self.set_location_finished:
            # this state is for attached walls only!
            mover.end()
            mover.o.select = False
            self.state = self.set_length
            # starting AlongLineMover
            mover = AlongSegmentMover(mover.wall, mover.o2)
            self.mover = mover
            mover.start()
        elif state is self.set_length:
            # this state is for attached walls only!
            operator = getLastOperator(context)
            # The condition operator != self.lastOperator means,
            # that the modal operator started by mover.start() finished its work
            if operator != self.lastOperator or event.type in {"RIGHTMOUSE", "ESC"}:
                # let cancel event happen, i.e. don't call mover.end() immediately
                self.state = self.finished
        elif state is self.finished:
            mover.end()
            return {"FINISHED"}
        return {"PASS_THROUGH"}

    def invoke(self, context, event):
        e = context.object
        locEnd = cursor_2d_to_location_3d(context, event)
        # try to get a wall instance assuming <e> is a corner EMPTY located at either free end of the wall
        wall = getWallFromEmpty(context, self, e, True)
        if wall:
            o = wall.extend(e, locEnd)
            bpy.ops.object.select_all(action="DESELECT")
            self.mover = AlongSegmentMover(wall, o)
            # set mode of operation
            self.attached = False
        else:
            # try to get a wall instance assuming <empty> is a segment EMPTY
            if e and "t" in e and e["t"] == "ws":
                wall = getWallFromEmpty(context, self, e, False)
                if wall:
                    # wall.startAttachedWall(empty, locEnd) returns segment EMPTY
                    o = wall.startAttachedWall(e, locEnd)
                    bpy.ops.object.select_all(action="DESELECT")
                    self.mover = SegmentMover(getWallFromEmpty(context, self, o), o)
                    # set mode of operation
                    self.attached = True
            if not wall:
                self.report({"ERROR"}, "To extend the wall, select an EMPTY object at either free end of the wall")
                return {"CANCELLED"}
        self.state = self.set_location
        self.lastOperator = getLastOperator(context)
        # The order how self.mover.start() and context.window_manager.modal_handler_add(self)
        # are called is important. If they are called in the reversed order, it won't be possible to
        # capture X, Y, Z keys
        self.mover.start()
        context.window_manager.modal_handler_add(self)
        return {"RUNNING_MODAL"}