LCOV - code coverage report
Current view: top level - gui/include/sketch - gui_sketch_card.inl (source / functions) Hit Total Coverage
Test: crystal-facet-uml_v1.61.0_covts Lines: 0 113 0.0 %
Date: 2024-10-26 21:44:38 Functions: 0 19 0.0 %

          Line data    Source code
       1             : /* File: gui_sketch_card.inl; Copyright and License: see below */
       2             : 
       3             : #include "u8/u8_log.h"
       4             : #include "u8/u8_trace.h"
       5             : #include "u8/u8_f64.h"
       6             : #include <assert.h>
       7             : 
       8           0 : static inline void gui_sketch_card_load_data( gui_sketch_card_t *this_,
       9             :                                               data_id_t diagram_id,
      10             :                                               data_database_reader_t *db_reader )
      11             : {
      12             :     /* load data to be drawn */
      13             :     const u8_error_t d_err
      14           0 :         = data_visible_set_load( &((*this_).painter_input_data), data_id_get_row_id( &diagram_id ), db_reader );
      15           0 :     if ( d_err != U8_ERROR_NONE )
      16             :     {
      17           0 :         U8_TRACE_INFO( "gui_sketch_card_load_data called on invalid database." );
      18             :     }
      19             :     const u8_error_t p_err
      20           0 :         = data_profile_part_load( &((*this_).profile), &((*this_).painter_input_data), db_reader );
      21           0 :     if ( p_err != U8_ERROR_NONE )
      22             :     {
      23           0 :         U8_TRACE_INFO( "data_profile_part_load() returned error." );
      24             :     }
      25           0 : }
      26             : 
      27             : static inline void gui_sketch_card_invalidate_data( gui_sketch_card_t *this_ )
      28             : {
      29             :     data_visible_set_invalidate( &((*this_).painter_input_data) );
      30             :     data_profile_part_reinit( &((*this_).profile) );
      31             : 
      32             : }
      33             : 
      34           0 : static inline bool gui_sketch_card_is_valid( const gui_sketch_card_t *this_ )
      35             : {
      36           0 :     return data_visible_set_is_valid( &((*this_).painter_input_data) );
      37             : }
      38             : 
      39           0 : static inline shape_int_rectangle_t gui_sketch_card_get_bounds( const gui_sketch_card_t *this_ )
      40             : {
      41           0 :     return (*this_).bounds;
      42             : }
      43             : 
      44           0 : static inline void gui_sketch_card_set_bounds( gui_sketch_card_t *this_, shape_int_rectangle_t bounds )
      45             : {
      46           0 :     (*this_).bounds = bounds;
      47           0 : }
      48             : 
      49           0 : static inline bool gui_sketch_card_is_visible( const gui_sketch_card_t *this_ )
      50             : {
      51           0 :     return (*this_).visible;
      52             : }
      53             : 
      54           0 : static inline void gui_sketch_card_set_visible( gui_sketch_card_t *this_, bool visible )
      55             : {
      56           0 :     (*this_).visible = visible;
      57           0 : }
      58             : 
      59           0 : static inline const data_diagram_t * gui_sketch_card_get_diagram_const ( const gui_sketch_card_t *this_ )
      60             : {
      61           0 :     return data_visible_set_get_diagram_const( &((*this_).painter_input_data) );
      62             : }
      63             : 
      64           0 : static inline data_diagram_t * gui_sketch_card_get_diagram_ptr ( gui_sketch_card_t *this_ )
      65             : {
      66           0 :     return data_visible_set_get_diagram_ptr( &((*this_).painter_input_data) );
      67             : }
      68             : 
      69           0 : static inline data_id_t gui_sketch_card_get_diagram_id ( const gui_sketch_card_t *this_ )
      70             : {
      71           0 :     const data_diagram_t *const diag = gui_sketch_card_get_diagram_const( this_ );
      72           0 :     return (diag==NULL) ? DATA_ID_VOID : data_diagram_get_data_id(diag);
      73             : }
      74             : 
      75           0 : static inline layout_order_t gui_sketch_card_get_order_at_pos( const gui_sketch_card_t *this_,
      76             :                                                                data_id_t obj_id,
      77             :                                                                int32_t x,
      78             :                                                                int32_t y )
      79             : {
      80             :     layout_order_t result;
      81             :     pencil_error_t pen_err;
      82             : 
      83           0 :     pen_err = pencil_diagram_maker_get_order_at_pos ( &((*this_).painter),
      84             :                                                       obj_id,
      85             :                                                       (double) x,
      86             :                                                       (double) y,
      87           0 :                                                       (*this_).snap_to_grid_distance,
      88             :                                                       &result
      89             :                                                     );
      90             : 
      91           0 :     switch ( pen_err )
      92             :     {
      93           0 :         case PENCIL_ERROR_NONE:
      94             :         {
      95             :             /* success */
      96             :         }
      97           0 :         break;
      98           0 :         case PENCIL_ERROR_OUT_OF_BOUNDS:
      99             :         {
     100           0 :             U8_TRACE_INFO( "PENCIL_ERROR_OUT_OF_BOUNDS in gui_sketch_card_get_order_at_pos" );
     101             :         }
     102           0 :         break;
     103           0 :         case PENCIL_ERROR_UNKNOWN_OBJECT:
     104             :         {
     105           0 :             U8_LOG_ANOMALY( "PENCIL_ERROR_UNKNOWN_OBJECT in gui_sketch_card_get_order_at_pos" );
     106             :         }
     107           0 :         break;
     108             :     }
     109             : 
     110           0 :     return result;
     111             : }
     112             : 
     113           0 : static inline int32_t gui_sketch_card_get_feature_order_at_pos ( const gui_sketch_card_t *this_,
     114             :                                                                  const data_feature_t *feature_ptr,
     115             :                                                                  int32_t x,
     116             :                                                                  int32_t y )
     117             : {
     118           0 :     assert ( NULL != feature_ptr );
     119             : 
     120             :     layout_order_t result;
     121             :     pencil_error_t pen_err;
     122             : 
     123           0 :     pen_err = pencil_diagram_maker_get_feature_order_at_pos ( &((*this_).painter),
     124             :                                                               feature_ptr,
     125             :                                                               (double) x,
     126             :                                                               (double) y,
     127             :                                                               &result
     128             :                                                             );
     129             : 
     130           0 :     switch ( pen_err )
     131             :     {
     132           0 :         case PENCIL_ERROR_NONE:
     133             :         {
     134             :             /* success */
     135             :         }
     136           0 :         break;
     137           0 :         case PENCIL_ERROR_OUT_OF_BOUNDS:
     138             :         {
     139           0 :             U8_TRACE_INFO( "PENCIL_ERROR_OUT_OF_BOUNDS in gui_sketch_card_get_feature_order_at_pos" );
     140             :         }
     141           0 :         break;
     142           0 :         case PENCIL_ERROR_UNKNOWN_OBJECT:
     143             :         {
     144           0 :             U8_LOG_ANOMALY( "PENCIL_ERROR_UNKNOWN_OBJECT in gui_sketch_card_get_feature_order_at_pos" );
     145             :         }
     146           0 :         break;
     147             :     }
     148             : 
     149           0 :     return layout_order_get_first( &result );
     150             : }
     151             : 
     152           0 : static inline void gui_sketch_card_get_grid_area ( const gui_sketch_card_t *this_,
     153             :                                                    shape_int_rectangle_t *out_bounds,
     154             :                                                    uint32_t *out_x_count,
     155             :                                                    uint32_t *out_y_count
     156             :                                                  )
     157             : {
     158           0 :     assert( out_bounds != NULL );
     159           0 :     assert( out_x_count != NULL );
     160           0 :     assert( out_y_count != NULL );
     161             : 
     162             :     double x0,y0,dx,dy;
     163             : 
     164           0 :     const geometry_grid_t *grid = pencil_diagram_maker_get_grid_const( &((*this_).painter) );
     165           0 :     const geometry_non_linear_scale_t *const x_scale = geometry_grid_get_x_scale_const( grid );
     166           0 :     const geometry_non_linear_scale_t *const y_scale = geometry_grid_get_y_scale_const( grid );
     167             : 
     168           0 :     x0 = geometry_non_linear_scale_get_location( x_scale, /*order=*/ INT32_MIN );
     169           0 :     dx = geometry_non_linear_scale_get_grid_distances( x_scale );
     170           0 :     *out_x_count = geometry_non_linear_scale_get_grid_intervals( x_scale ) + 1;
     171             : 
     172           0 :     y0 = geometry_non_linear_scale_get_location( y_scale, /*order=*/ INT32_MIN );
     173           0 :     dy = geometry_non_linear_scale_get_grid_distances( y_scale );
     174           0 :     *out_y_count = geometry_non_linear_scale_get_grid_intervals( y_scale ) + 1;
     175             : 
     176           0 :     shape_int_rectangle_init( out_bounds,
     177             :                               (int32_t) x0,
     178             :                               (int32_t) y0,
     179           0 :                               (uint32_t) ((*out_x_count>2) ? ((*out_x_count-1)*dx) : dx),
     180           0 :                               (uint32_t) ((*out_y_count>2) ? ((*out_y_count-1)*dy) : dy)
     181             :                             );
     182           0 : }
     183             : 
     184           0 : static inline const geometry_grid_t *gui_sketch_card_get_grid_const ( const gui_sketch_card_t *this_ )
     185             : {
     186           0 :     return pencil_diagram_maker_get_grid_const( &((*this_).painter) );
     187             : }
     188             : 
     189           0 : static inline bool gui_sketch_card_needs_layout( const gui_sketch_card_t *this_ )
     190             : {
     191           0 :     return (*this_).dirty_elements_layout;
     192             : }
     193             : 
     194           0 : static inline void gui_sketch_card_layout_elements( gui_sketch_card_t *this_, cairo_t *cr )
     195             : {
     196           0 :     pencil_diagram_maker_layout_elements ( &((*this_).painter), NULL, cr );
     197           0 :     (*this_).dirty_elements_layout = false;
     198           0 : }
     199             : 
     200           0 : static inline void gui_sketch_card_do_layout( gui_sketch_card_t *this_, cairo_t *cr )
     201             : {
     202           0 :     if ( gui_sketch_card_is_valid( this_ ) )
     203             :     {
     204             :         /* layout loaded classifiers */
     205           0 :         const int32_t left = shape_int_rectangle_get_left( &((*this_).bounds) );
     206           0 :         const int32_t top = shape_int_rectangle_get_top( &((*this_).bounds) );
     207           0 :         const uint32_t width = shape_int_rectangle_get_width( &((*this_).bounds) );
     208           0 :         const uint32_t height = shape_int_rectangle_get_height( &((*this_).bounds) );
     209             : 
     210             :         geometry_rectangle_t destination;
     211           0 :         geometry_rectangle_init( &destination, left, top, width, height );
     212             : 
     213           0 :         pencil_diagram_maker_define_grid ( &((*this_).painter), destination, cr );
     214           0 :         pencil_diagram_maker_layout_elements ( &((*this_).painter), NULL, cr );
     215           0 :         (*this_).dirty_elements_layout = false;
     216             : 
     217           0 :         geometry_rectangle_destroy( &destination );
     218             :     }
     219             :     else
     220             :     {
     221           0 :         U8_TRACE_INFO( "gui_sketch_card_do_layout called on invalid card." );
     222             :     }
     223           0 : }
     224             : 
     225           0 : static inline const layout_visible_set_t * gui_sketch_card_get_visible_set( const gui_sketch_card_t *this_ )
     226             : {
     227           0 :     return pencil_diagram_maker_get_layout_data_const( &((*this_).painter) );
     228             : }
     229             : 
     230           0 : static inline int32_t gui_sketch_card_get_highest_rel_list_order( const gui_sketch_card_t *this_ )
     231             : {
     232           0 :     int32_t result = 0;
     233             : 
     234           0 :     if ( data_visible_set_is_valid( &((*this_).painter_input_data) ) )
     235             :     {
     236           0 :         for ( uint32_t rs_idx = 0; rs_idx < data_visible_set_get_relationship_count( &((*this_).painter_input_data) ); rs_idx ++ )
     237             :         {
     238             :             const data_relationship_t *relation;
     239           0 :             relation = data_visible_set_get_relationship_const ( &((*this_).painter_input_data), rs_idx );
     240           0 :             if ( data_relationship_get_list_order( relation ) > result )
     241             :             {
     242           0 :                 result = data_relationship_get_list_order( relation );
     243             :             }
     244             :         }
     245             :     }
     246             : 
     247           0 :     return result;
     248             : }
     249             : 
     250           0 : static inline int32_t gui_sketch_card_get_highest_feat_list_order( const gui_sketch_card_t *this_, data_id_t classifier_id )
     251             : {
     252           0 :     int32_t result = 0;
     253             : 
     254           0 :     if ( data_visible_set_is_valid( &((*this_).painter_input_data) ) )
     255             :     {
     256           0 :         for ( uint32_t f_idx = 0; f_idx < data_visible_set_get_feature_count( &((*this_).painter_input_data) ); f_idx ++ )
     257             :         {
     258             :             const data_feature_t *const feat
     259           0 :                 = data_visible_set_get_feature_const ( &((*this_).painter_input_data), f_idx );
     260           0 :             assert( feat != NULL );
     261           0 :             const data_feature_type_t f_type = data_feature_get_main_type( feat );
     262           0 :             if (( f_type == DATA_FEATURE_TYPE_PROPERTY )||( f_type == DATA_FEATURE_TYPE_OPERATION ))
     263             :             {
     264           0 :                 if ( data_feature_get_classifier_row_id( feat ) == data_id_get_row_id( &classifier_id ) )
     265             :                 {
     266           0 :                     if ( data_feature_get_list_order( feat ) > result )
     267             :                     {
     268           0 :                         result = data_feature_get_list_order( feat );
     269             :                     }
     270             :                 }
     271             :             }
     272             :         }
     273             :     }
     274             : 
     275           0 :     return result;
     276             : }
     277             : 
     278             : 
     279             : /*
     280             : Copyright 2016-2024 Andreas Warnke
     281             : 
     282             : Licensed under the Apache License, Version 2.0 (the "License");
     283             : you may not use this file except in compliance with the License.
     284             : You may obtain a copy of the License at
     285             : 
     286             :     http://www.apache.org/licenses/LICENSE-2.0
     287             : 
     288             : Unless required by applicable law or agreed to in writing, software
     289             : distributed under the License is distributed on an "AS IS" BASIS,
     290             : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     291             : See the License for the specific language governing permissions and
     292             : limitations under the License.
     293             : */

Generated by: LCOV version 1.16