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"}
def modal(self, context, event): operator = getLastOperator(context) if event.type in {"X", "Y", "Z"}: # capture X, Y, Z keys return {"RUNNING_MODAL"} if self.finished: self.mover.end() return {"FINISHED"} if operator != self.lastOperator or event.type in {"RIGHTMOUSE", "ESC"}: # let cancel event happen, i.e. don't call op.mover.end() immediately self.finished = True return {"PASS_THROUGH"}
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 modal(self, context, event): operator = getLastOperator(context) if event.type in {'X', 'Y', 'Z'}: # capture X, Y, Z keys return {'RUNNING_MODAL'} if self.finished: self.mover.end() return {'FINISHED'} if operator != self.lastOperator or event.type in { 'RIGHTMOUSE', 'ESC' }: # let cancel event happen, i.e. don't call op.mover.end() immediately self.finished = True return {'PASS_THROUGH'}
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'}
def move_modal(self, op, context, event, o): operator = getLastOperator(context) if op.allowZ and event.type == "Z": op.allowZ = False return {'PASS_THROUGH'} elif event.type in {'X', 'Y', 'Z'}: # capture X, Y, Z keys return {'RUNNING_MODAL'} if op.finished: op.mover.end() return {'FINISHED'} if operator != op.lastOperator or event.type in {'RIGHTMOUSE', 'ESC'}: # let cancel event happen, i.e. don't call op.mover.end() immediately op.finished = True return {'PASS_THROUGH'}
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"}
def move_invoke(self, op, context, event, o): op.allowZ = False if o["t"] == self.type: mover = AlongWallMover(self) op.allowZ = self.allowZ elif o["t"] == "width": mover = SizeMover(self, o) elif o["t"] == "height": mover = SizeMover(self, o) # keep the following variables in the operator <o> op.state = None op.lastOperator = getLastOperator(context) op.mover = mover op.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(op) return {'RUNNING_MODAL'}
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'}