add_child Function

private function add_child(self, child) result(ok)

Add child to this frame's children. Returns false (and does nothing) for this frame itself or an ancestor of it; true if it is already a child.

A scene: the Earth, with a spacecraft and the Moon as its children (their positions are relative to it):

earth = Sphere('Earth', radius=6378.137_wp)
craft = Sphere('Spacecraft', radius=200.0_wp, color=[1.0_wp, 0.3_wp, 0.2_wp])
moon = Sphere('Moon', radius=1737.4_wp)
call moon%set_position([384400.0_wp, 0.0_wp, 0.0_wp])
if (.not. (earth%add_child(craft) .and. earth%add_child(moon))) error stop 'add_child failed'
scene = FrameManager(earth)

Type Bound

ReferenceFrame

Arguments

Type IntentOptional Attributes Name
class(ReferenceFrame), intent(inout), target :: self
class(ReferenceFrame), intent(inout), target :: child

the frame to add (not owned)

Return Value logical


Calls

proc~~add_child~~CallsGraph proc~add_child ReferenceFrame%add_child interface~vkf_compile_node vkf_compile_node proc~add_child->interface~vkf_compile_node interface~vkf_node_add_child vkf_node_add_child proc~add_child->interface~vkf_node_add_child interface~vkf_viewer_any vkf_viewer_any proc~add_child->interface~vkf_viewer_any proc~append~2 append proc~add_child->proc~append~2 proc~check_status check_status proc~add_child->proc~check_status proc~child_index ReferenceFrame%child_index proc~add_child->proc~child_index proc~is_descendant is_descendant proc~add_child->proc~is_descendant proc~next_motion_stamp next_motion_stamp proc~add_child->proc~next_motion_stamp proc~realize ReferenceFrame%realize proc~add_child->proc~realize proc~same_frame same_frame proc~add_child->proc~same_frame proc~find find proc~child_index->proc~find proc~is_descendant->proc~is_descendant proc~is_descendant->proc~same_frame proc~realize->interface~vkf_node_add_child proc~realize->proc~check_status proc~realize->proc~realize interface~vkf_switch_create vkf_switch_create proc~realize->interface~vkf_switch_create interface~vkf_switch_set vkf_switch_set proc~realize->interface~vkf_switch_set interface~vkf_transform_create vkf_transform_create proc~realize->interface~vkf_transform_create proc~build_contents ReferenceFrame%build_contents proc~realize->proc~build_contents proc~build_decorations build_decorations proc~realize->proc~build_decorations proc~build_light build_light proc~realize->proc~build_light proc~sync ReferenceFrame%sync proc~realize->proc~sync proc~build_decorations->interface~vkf_node_add_child proc~build_decorations->proc~check_status proc~build_decorations->interface~vkf_switch_create proc~make_axis make_axis proc~build_decorations->proc~make_axis proc~make_name_label make_name_label proc~build_decorations->proc~make_name_label proc~reposition_axes ReferenceFrame%reposition_axes proc~build_decorations->proc~reposition_axes proc~update_switches update_switches proc~build_decorations->proc~update_switches proc~build_light->interface~vkf_node_add_child proc~build_light->proc~check_status proc~build_light->interface~vkf_switch_create interface~vkf_light_create vkf_light_create proc~build_light->interface~vkf_light_create proc~apply_light apply_light proc~build_light->proc~apply_light proc~sync->proc~check_status proc~sync->proc~sync interface~vkf_transform_set_matrix vkf_transform_set_matrix proc~sync->interface~vkf_transform_set_matrix proc~local_matrix ReferenceFrame%local_matrix proc~sync->proc~local_matrix proc~apply_light->proc~check_status interface~vkf_light_set vkf_light_set proc~apply_light->interface~vkf_light_set proc~frame_matrix frame_matrix proc~local_matrix->proc~frame_matrix proc~make_axis->proc~update_switches proc~arrow_create arrow_create proc~make_axis->proc~arrow_create proc~axis_label ReferenceFrame%axis_label proc~make_axis->proc~axis_label proc~label_create label_create proc~make_axis->proc~label_create proc~label_font ReferenceFrame%label_font proc~make_axis->proc~label_font proc~replace_child replace_child proc~make_axis->proc~replace_child proc~make_name_label->proc~check_status proc~make_name_label->proc~update_switches interface~vkf_label_set_on_top vkf_label_set_on_top proc~make_name_label->interface~vkf_label_set_on_top proc~make_name_label->proc~label_create proc~make_name_label->proc~label_font proc~name ReferenceFrame%name proc~make_name_label->proc~name proc~make_name_label->proc~replace_child proc~bound ReferenceFrame%bound proc~reposition_axes->proc~bound proc~update_switches->proc~check_status proc~update_switches->interface~vkf_switch_set interface~vkf_mesh_create vkf_mesh_create proc~arrow_create->interface~vkf_mesh_create proc~arrow arrow proc~arrow_create->proc~arrow proc~arrow_size arrow_size proc~arrow_create->proc~arrow_size proc~mesh_arrays mesh_arrays proc~arrow_create->proc~mesh_arrays proc~quat_to_matrix quat_to_matrix proc~frame_matrix->proc~quat_to_matrix interface~vkf_label_create vkf_label_create proc~label_create->interface~vkf_label_create proc~get_font get_font proc~label_create->proc~get_font proc~vsg_alignment vsg_alignment proc~label_create->proc~vsg_alignment proc~replace_child->interface~vkf_compile_node proc~replace_child->interface~vkf_node_add_child proc~replace_child->proc~check_status interface~vkf_node_delete vkf_node_delete proc~replace_child->interface~vkf_node_delete interface~vkf_node_remove_child vkf_node_remove_child proc~replace_child->interface~vkf_node_remove_child proc~cross cross proc~arrow->proc~cross interface~vkf_font_read vkf_font_read proc~get_font->interface~vkf_font_read proc~find_font find_font proc~get_font->proc~find_font interface~vkf_mesh_array vkf_mesh_array proc~mesh_arrays->interface~vkf_mesh_array proc~find_in_dirs find_in_dirs proc~find_font->proc~find_in_dirs

Source Code

    logical function add_child(self, child) result(ok)
        class(ReferenceFrame), intent(inout), target :: self
        class(ReferenceFrame), intent(inout), target :: child !! the frame to add (not owned)
        ok = .false.
        if (same_frame(self, child)) return
        if (self%child_index(child) > 0) then
            ok = .true.
            return
        end if
        if (is_descendant(child, self)) return
        call append(self%children, self%n_children, child)
        call append(child%parents, child%n_parents, self)
        if (child%n_parents == 1) child%stamp_ = next_motion_stamp()   ! (its first parent: where it is)
        ok = .true.
        if (self%realized) then                         ! shown: draw the child from the next frame
            if (.not. child%realized) then
                if (self%shown_) then                   ! (for a window that exists now)
                    call child%realize(vkf_viewer_any())
                    call check_status(vkf_compile_node(child%node_))
                else
                    call child%realize(c_null_ptr)
                end if
            end if
            call check_status(vkf_node_add_child(self%node_, child%node_))
        end if
    end function add_child