def modal(self, context, event):
        mouse.set_event(event)

        if event.type == 'MOUSEMOVE':  # Apply
            pass
            #self.value = event.mouse_x
            #self.execute(context)
        elif event.type == 'LEFTMOUSE':  # Confirm
            print('self.POINTS')
            print(self.POINTS)
            ToolDetail.prepare_locations(ToolDetail, self.POINTS)
            return {'FINISHED'}
        elif event.type == 'RIGHTMOUSE':  # Cancel
            # print(dir(event))
            # print(event.value)
            if (event.value == 'RELEASE'):
                self.check_find_point(mouse.get_coords_location_3d())

            #print(event)
            # print('context.selected_objects')
            # print(context.selected_objects)
            # print('event.mouse_x '+str(event.mouse_x))
            # print(mouse.get_coords_location_3d())
            # print('event.mouse_y '+str(event.mouse_y))
            #bpy.data.objects["Точка.004"].select = True

            #return {'RUNNING_MODAL'}

        return {'RUNNING_MODAL'}
 def draw_callback(self, context):
     global TARGET_LOCATION
     mouse_coords_3 = mouse.get_coords_location_3d()
     if ((not mouse_coords_3) or (not mouse_coords_3[2] == 0.0)):
         return
     first = (0, 0, 0)
     second = mouse_coords_3
     self.draw_point(context, (second, ))
     TARGET_LOCATION = mouse_coords_3
Example #3
0
  def draw_callback(self, context):
    global TARGET_LOCATION
    global ANGLE
    mouse_coords_3 = mouse.get_coords_location_3d()
    first_object = context.active_object
    second_object = [oth for oth in context.selected_objects if oth.fp_id > 0 and oth.fp_id != context.active_object.fp_id]
    if (
          (not mouse_coords_3) 
          or 
          (not mouse_coords_3[2] == 0.0)
      ): 
      return
    if (mouse.is_window_event() or True):
      if first_object.fp_type == BezierCurve.FP_TYPE:
        locations_curve = [
          get_point_abs_location(item) for item in bpy.data.objects
          if item.fp_id > 0 and item.fp_id in first_object.fp_deps
        ]
        handle_left = [first_object.data.splines[0].bezier_points[0].handle_right[0] - first_object.data.splines[0].bezier_points[0].co[0] + locations_curve[0][0],first_object.data.splines[0].bezier_points[0].handle_right[1] - first_object.data.splines[0].bezier_points[0].co[1] + locations_curve[0][1],0.0]
        handle_right = [first_object.data.splines[0].bezier_points[1].handle_left[0] - first_object.data.splines[0].bezier_points[1].co[0] + locations_curve[1][0],first_object.data.splines[0].bezier_points[1].handle_left[1] - first_object.data.splines[0].bezier_points[1].co[1] + locations_curve[1][1],0.0]
        locations = get_point_abs_location(second_object[0])
      else:
        locations_curve = [
          get_point_abs_location(item) for item in bpy.data.objects
          if item.fp_id > 0 and item.fp_id in second_object[0].fp_deps
        ]
        handle_left = [second_object[0].data.splines[0].bezier_points[0].handle_right[0] - second_object[0].data.splines[0].bezier_points[0].co[0] + locations_curve[0][0],second_object[0].data.splines[0].bezier_points[0].handle_right[1] - second_object[0].data.splines[0].bezier_points[0].co[1] + locations_curve[0][1],0.0]
        handle_right = [second_object[0].data.splines[0].bezier_points[1].handle_left[0] - second_object[0].data.splines[0].bezier_points[1].co[0] + locations_curve[1][0],second_object[0].data.splines[0].bezier_points[1].handle_left[1] - second_object[0].data.splines[0].bezier_points[1].co[1] + locations_curve[1][1],0.0]
        locations = get_point_abs_location(first_object)

      coef_k = (mouse_coords_3[1] - locations[1])/(mouse_coords_3[0] - locations[0])
      # COEF_B = -coef_k * locations[0] + locations[1]
      if locations[0] < mouse_coords_3[0]:
        ANGLE = 180 + degrees(atan(coef_k))
      else:
        ANGLE = degrees(atan(coef_k))

      line_length = sqrt((locations[0]-mouse_coords_3[0]) ** 2 + (locations[1]-mouse_coords_3[1]) ** 2)
      proportion = 10000/line_length
      def_loc_point = [locations[i] - mouse_coords_3[i] for i in range(3)]
      def_loc_mouse = [mouse_coords_3[i] - locations[i] for i in range(3)]

      location = [[0,0],[0,0]]
      location[0][0] = def_loc_point[0] * proportion + mouse_coords_3[0]
      location[0][1] = def_loc_point[1] * proportion + mouse_coords_3[1]
      location[1][0] = def_loc_mouse[0] * proportion + mouse_coords_3[0]
      location[1][1] = def_loc_mouse[1] * proportion + mouse_coords_3[1]

      self.draw_line(context, ((location[0][0], location[0][1], 0.0), (location[1][0], location[1][1], 0.0)))
      
      coords_points = line_to_curve({"x": location[0][0], "y": location[0][1]},{"x": location[1][0], "y": location[1][1]}, {"x": locations_curve[0][0], "y": locations_curve[0][1]}, {"x": handle_left[0], "y": handle_left[1]}, {"x": handle_right[0], "y": handle_right[1]}, {"x": locations_curve[1][0], "y": locations_curve[1][1]})
      for coords_point in coords_points["points"]:
        vector_coords_point = (coords_point["x"], coords_point["y"], 0.0)
        if vector_coords_point[0] != -10000:
          self.draw_point(context, (vector_coords_point,))

      TARGET_LOCATION = vector_coords_point
Example #4
0
 def draw_callback(self, context):
     global TARGET_LOCATION
     mouse_coords_2 = mouse.get_rel_coords_region_2d()
     mouse_coords_3 = mouse.get_coords_location_3d()
     if ((not mouse_coords_3) or (not mouse_coords_3[2] == 0.0)):
         return
     if (mouse.is_window_event() or True):
         first = get_point_abs_location(context.active_object)
         second = self._get_second_location(context, mouse_coords_3, first)
         self.draw_line(context, (first, second))
         self.draw_point(context, (second, ))
         TARGET_LOCATION = second
Example #5
0
    def draw_callback(self, context):
        global TARGET_LOCATION, _ANGLE, FLAG, IMAX, IMIN
        mouse_coords_3 = mouse.get_coords_location_3d()
        if FLAG:
            TARGET_LOCATION = mouse_coords_3
        self.DIF = mouse_coords_3[0] - TARGET_LOCATION[0]
        if mouse.get_event()[4] == 'TAB' and FLAG:
            TARGET_LOCATION = mouse_coords_3
            FLAG = False
        TARGET_LOCATION = mouse_coords_3

        _ANGLE = self.DIF * 5

        dart_line = [
            line for line in context.selected_objects
            if line.fp_type == LineForDart.FP_TYPE
        ]

        if dart_line[0].fp_deps[0] == dart_line[1].fp_deps[0]:
            for obj in bpy.data.objects:
                if obj.fp_id == dart_line[0].fp_deps[0]:
                    center = obj
                    break
        elif dart_line[0].fp_deps[0] == dart_line[1].fp_deps[1]:
            for obj in bpy.data.objects:
                if obj.fp_id == dart_line[0].fp_deps[0]:
                    center = obj
                    break
        else:
            for obj in bpy.data.objects:
                if obj.fp_id == dart_line[0].fp_deps[1]:
                    center = obj
                    break

        points_on_dart_line = []
        for line in dart_line:
            tmp_pts = [center]
            for obj in bpy.data.objects:
                if (obj.fp_id == line.fp_deps[0]
                        or obj.fp_id == line.fp_deps[1]) and obj != center:
                    tmp_pts += [obj]
            points_on_dart_line += [tmp_pts]

        angle_dart_line = []
        for points in points_on_dart_line:
            angle_dart_line += [
                get_absolute_angle(get_point_abs_location(points[0]),
                                   get_point_abs_location(points[1]))
            ]

        all_limit_lines = []
        for line in bpy.data.objects:
            if (line.fp_deps[0] == center.fp_id
                    or line.fp_deps[1] == center.fp_id
                ) and line != dart_line[0] and line != dart_line[1]:
                all_limit_lines += [line]

        all_point_on_limit_lines = []
        for line in all_limit_lines:
            tmp_pts = [center]
            for obj in bpy.data.objects:
                if (obj.fp_id == line.fp_deps[0]
                        or obj.fp_id == line.fp_deps[1]) and obj != center:
                    tmp_pts += [obj]
            all_point_on_limit_lines += [tmp_pts]
        angle_limit_line = []
        for points in all_point_on_limit_lines:
            angle_limit_line += [
                get_absolute_angle(get_point_abs_location(points[0]),
                                   get_point_abs_location(points[1]))
            ]

        angle_limit = []
        limit_lines = []
        tmp_min = 10000
        tmp_max = -10000
        if angle_dart_line[0] < angle_dart_line[1]:
            for angle in angle_limit_line:
                if angle > tmp_max and angle <= angle_dart_line[0]:
                    tmp_max = angle
            if tmp_max == -10000:
                angle_limit += [min(angle_limit_line)]
            else:
                angle_limit += [tmp_max]
            for angle in angle_limit_line:
                if angle < tmp_min and angle >= angle_dart_line[1]:
                    tmp_min = angle
            if tmp_min == 10000:
                angle_limit += [max(angle_limit_line)]
            else:
                angle_limit += [tmp_min]
        else:
            for angle in angle_limit_line:
                if angle < tmp_min and angle >= angle_dart_line[0]:
                    tmp_min = angle
            if tmp_min == 10000:
                angle_limit += [max(angle_limit_line)]
            else:
                angle_limit += [tmp_min]
            for angle in angle_limit_line:
                if angle > tmp_max and angle <= angle_dart_line[1]:
                    tmp_max = angle
            if tmp_max == -10000:
                angle_limit += [min(angle_limit_line)]
            else:
                angle_limit += [tmp_max]
        for angle in angle_limit:
            for i in range(len(all_limit_lines)):
                if angle_limit_line[i] == angle:
                    limit_lines += [all_limit_lines[i]]
                    break

        dif_angle = [
            round(angle_dart_line[i] - angle_limit[i], 1)
            for i in range(len(angle_limit))
        ]
        if FLAG:
            if dif_angle[0] > 0:
                IMAX = 0
                IMIN = 1
            else:
                IMAX = 1
                IMIN = 0
        for i in range(len(dif_angle)):
            if i == IMAX:
                print("_ANGLE", _ANGLE)
                if _ANGLE < 0 and dif_angle[i] < 0.9:
                    _ANGLE = 0
            if i == IMIN:
                print("_ANGLE", _ANGLE)
                if _ANGLE > 0 and dif_angle[i] > -0.9:
                    _ANGLE = 0

        points_deps_for_update = []
        points_parent_for_update = []
        point_start_for_update = []
        all_points_of_select = []
        for obj in context.selected_objects:
            count = 0
            for point in bpy.data.objects:
                if (obj.fp_deps[0] == point.fp_id or obj.fp_deps[1]
                        == point.fp_id) and is_one_of_points(point) and all(
                            point != p for p in all_points_of_select):
                    all_points_of_select += [point]
                    count += 1
                if count == 2:
                    break
        for point in all_points_of_select:
            if point.fp_id == 1:
                point_start_for_update += [point]
                continue
            for obj in bpy.data.objects:
                if obj.parent == point and all(obj != p
                                               for p in all_points_of_select):
                    points_deps_for_update += [obj]
                if point.parent == obj and all(
                        obj != p
                        for p in all_points_of_select) and point != center:
                    points_parent_for_update += [point]

        if len(points_deps_for_update) > 0:
            old_location = []
            for point in points_deps_for_update:
                old_location += [get_point_abs_location(point)]

        if len(point_start_for_update) > 0:
            R = round(
                get_distance(get_point_abs_location(point_start_for_update[0]),
                             get_point_abs_location(center)), 3)
            angle = round(
                get_absolute_angle(
                    get_point_abs_location(center),
                    get_point_abs_location(point_start_for_update[0])), 1)
            location_center = get_point_abs_location(center)
            angle += _ANGLE
            new_location = []
            new_location += [location_center[0] + R * cos(angle * pi / 180)]
            new_location += [location_center[1] + R * sin(angle * pi / 180)]
            distance = round(get_distance([0, 0], new_location), 3)
            new_angle = round(get_angle([0, 0], new_location), 1)

            point_start_for_update[0].fp_expression = str(distance)
            point_start_for_update[0].fp_angle = new_angle

            if center.parent == point_start_for_update[0]:
                center.fp_angle += _ANGLE
        elif len(points_parent_for_update) > 0:
            R = round(
                get_distance(
                    get_point_abs_location(points_parent_for_update[0]),
                    get_point_abs_location(center)), 3)
            angle = round(
                get_absolute_angle(
                    get_point_abs_location(center),
                    get_point_abs_location(points_parent_for_update[0])), 1)
            location_center = get_point_abs_location(center)
            angle += _ANGLE
            new_location = []
            new_location += [location_center[0] + R * cos(angle * pi / 180)]
            new_location += [location_center[1] + R * sin(angle * pi / 180)]
            distance = round(
                get_distance(
                    get_point_abs_location(points_parent_for_update[0].parent),
                    new_location), 3)
            new_angle = round(
                get_angle(
                    get_point_abs_location(points_parent_for_update[0].parent),
                    new_location), 1)

            points_parent_for_update[0].fp_expression = str(distance)
            points_parent_for_update[0].fp_angle = new_angle

            if center.parent == points_parent_for_update[0]:
                center.fp_angle += _ANGLE

        for point in all_points_of_select:
            if point != center and all(
                    point != obj for obj in point_start_for_update) and all(
                        point != obj
                        for obj in points_parent_for_update) and all(
                            point != obj for obj in points_deps_for_update):
                point.fp_angle += _ANGLE

        if len(points_deps_for_update) > 0:
            new_location_parent = []
            for point in points_deps_for_update:
                new_location_parent += [get_point_abs_location(point.parent)]
            for i in range(len(points_deps_for_update)):
                distance = round(
                    get_distance(new_location_parent[i], old_location[i]), 3)
                new_angle = round(
                    get_angle(new_location_parent[i], old_location[i]), 1)
                points_deps_for_update[i].fp_expression = str(distance)
                points_deps_for_update[i].fp_angle = new_angle
Example #6
0
 def on_before_modal(self):
     global OAAT_LOCK
     self.TARGET_LOCATION = mouse.get_coords_location_3d()
     OAAT_LOCK = True
Example #7
0
    def draw_callback(self, context):
        global TARGET_LOCATION
        global ANGLE
        mouse_coords_3 = mouse.get_coords_location_3d()
        first_object = context.active_object
        second_object = [
            oth for oth in context.selected_objects
            if oth.fp_id > 0 and oth.fp_id != context.active_object.fp_id
        ]
        if ((not mouse_coords_3) or (not mouse_coords_3[2] == 0.0)):
            return
        if (mouse.is_window_event() or True):
            if first_object.fp_type == Arc.FP_TYPE:
                angles = first_object.fp_angles
                point_center_arc = get_point_abs_location(first_object.parent)
                radius_arc = expression_to_value(first_object.fp_expression)
                locations = get_point_abs_location(second_object[0])
            else:
                angles = second_object[0].fp_angles
                point_center_arc = get_point_abs_location(
                    second_object[0].parent)
                radius_arc = expression_to_value(
                    second_object[0].fp_expression)
                locations = get_point_abs_location(first_object)

            coef_k = (mouse_coords_3[1] - locations[1]) / (mouse_coords_3[0] -
                                                           locations[0])
            if locations[0] < mouse_coords_3[0]:
                ANGLE = 180 + degrees(atan(coef_k))
            else:
                ANGLE = degrees(atan(coef_k))

            line_length = sqrt((locations[0] - mouse_coords_3[0])**2 +
                               (locations[1] - mouse_coords_3[1])**2)
            proportion = 10000 / line_length
            def_loc_point = [
                locations[i] - mouse_coords_3[i] for i in range(3)
            ]
            def_loc_mouse = [
                mouse_coords_3[i] - locations[i] for i in range(3)
            ]

            location = [[0, 0], [0, 0]]
            location[0][0] = def_loc_point[0] * proportion + mouse_coords_3[0]
            location[0][1] = def_loc_point[1] * proportion + mouse_coords_3[1]
            location[1][0] = def_loc_mouse[0] * proportion + mouse_coords_3[0]
            location[1][1] = def_loc_mouse[1] * proportion + mouse_coords_3[1]

            self.draw_line(context, ((location[0][0], location[0][1], 0.0),
                                     (location[1][0], location[1][1], 0.0)))

            coords_points = line_to_arc({
                "x": locations[0],
                "y": locations[1]
            }, {
                "x": mouse_coords_3[0],
                "y": mouse_coords_3[1]
            }, point_center_arc, angles[0], angles[1], radius_arc)
            for coords_point in coords_points["points"]:
                vector_coords_point = (coords_point["x"], coords_point["y"],
                                       0.0)
                if vector_coords_point[0] != -10000:
                    self.draw_point(context, (vector_coords_point, ))
                    TARGET_LOCATION = vector_coords_point
    def draw_callback(self, context):
        global TARGET_LOCATION
        global ANGLE
        mouse_coords_3 = mouse.get_coords_location_3d()
        first_object = context.active_object
        second_object = [
            oth for oth in context.selected_objects
            if oth.fp_id > 0 and oth.fp_id != context.active_object.fp_id
        ]
        if ((not mouse_coords_3) or (not mouse_coords_3[2] == 0.0)):
            return
        if (mouse.is_window_event() or True):
            if first_object.fp_type == Line.FP_TYPE:
                collection_of_line1_points = ([
                    d for d in bpy.data.objects
                    if (d.fp_id == first_object.fp_deps[0]
                        or d.fp_id == first_object.fp_deps[1]) and d.fp_id > 0
                ])
                locations1 = [
                    get_point_abs_location(point)
                    for point in collection_of_line1_points
                ]
                locations = get_point_abs_location(second_object[0])
            else:
                collection_of_line1_points = ([
                    d for d in bpy.data.objects
                    if (d.fp_id == second_object[0].fp_deps[0] or d.fp_id ==
                        second_object[0].fp_deps[1]) and d.fp_id > 0
                ])
                locations1 = [
                    get_point_abs_location(point)
                    for point in collection_of_line1_points
                ]
                locations = get_point_abs_location(first_object)

            coef_k = (mouse_coords_3[1] - locations[1]) / (mouse_coords_3[0] -
                                                           locations[0])
            if locations[0] < mouse_coords_3[0]:
                ANGLE = 180 + degrees(atan(coef_k))
            else:
                ANGLE = degrees(atan(coef_k))

            line_length = sqrt((locations[0] - mouse_coords_3[0])**2 +
                               (locations[1] - mouse_coords_3[1])**2)
            proportion = 10000 / line_length
            def_loc_point = [
                locations[i] - mouse_coords_3[i] for i in range(3)
            ]
            def_loc_mouse = [
                mouse_coords_3[i] - locations[i] for i in range(3)
            ]

            location = [[0, 0], [0, 0]]
            location[0][0] = def_loc_point[0] * proportion + mouse_coords_3[0]
            location[0][1] = def_loc_point[1] * proportion + mouse_coords_3[1]
            location[1][0] = def_loc_mouse[0] * proportion + mouse_coords_3[0]
            location[1][1] = def_loc_mouse[1] * proportion + mouse_coords_3[1]

            self.draw_line(context, ((location[0][0], location[0][1], 0.0),
                                     (location[1][0], location[1][1], 0.0)))

            coords_points = line_to_line(
                {
                    "x": locations1[0][0],
                    "y": locations1[0][1]
                }, {
                    "x": locations1[1][0],
                    "y": locations1[1][1]
                }, {
                    "x": locations[0],
                    "y": locations[1]
                }, {
                    "x": mouse_coords_3[0],
                    "y": mouse_coords_3[1]
                })
            vector_coords_point = (coords_points["points"][0]["x"],
                                   coords_points["points"][0]["y"], 0.0)
            self.draw_point(context, (vector_coords_point, ))
            TARGET_LOCATION = vector_coords_point