LCOV - code coverage report
Current view: top level - gui/include/sketch - gui_sketch_card.inl (source / functions) Coverage Total Hit
Test: crystal-facet-uml_v1.63.2_covts Lines: 0.0 % 113 0
Test Date: 2025-05-01 10:10:14 Functions: 0.0 % 19 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 :     const double snap_to_grid = gui_sketch_style_get_snap_to_grid( &((*this_).sketch_style) );
      84            0 :     pen_err = pencil_diagram_maker_get_order_at_pos ( &((*this_).painter),
      85              :                                                       obj_id,
      86              :                                                       (double) x,
      87              :                                                       (double) y,
      88              :                                                       snap_to_grid,
      89              :                                                       &result
      90              :                                                     );
      91              : 
      92            0 :     switch ( pen_err )
      93              :     {
      94            0 :         case PENCIL_ERROR_NONE:
      95              :         {
      96              :             /* success */
      97              :         }
      98            0 :         break;
      99            0 :         case PENCIL_ERROR_OUT_OF_BOUNDS:
     100              :         {
     101            0 :             U8_TRACE_INFO( "PENCIL_ERROR_OUT_OF_BOUNDS in gui_sketch_card_get_order_at_pos" );
     102              :         }
     103            0 :         break;
     104            0 :         case PENCIL_ERROR_UNKNOWN_OBJECT:
     105              :         {
     106            0 :             U8_LOG_ANOMALY( "PENCIL_ERROR_UNKNOWN_OBJECT in gui_sketch_card_get_order_at_pos" );
     107              :         }
     108            0 :         break;
     109              :     }
     110              : 
     111            0 :     return result;
     112              : }
     113              : 
     114            0 : static inline int32_t gui_sketch_card_get_feature_order_at_pos ( const gui_sketch_card_t *this_,
     115              :                                                                  const data_feature_t *feature_ptr,
     116              :                                                                  int32_t x,
     117              :                                                                  int32_t y )
     118              : {
     119            0 :     assert ( NULL != feature_ptr );
     120              : 
     121              :     layout_order_t result;
     122              :     pencil_error_t pen_err;
     123              : 
     124            0 :     pen_err = pencil_diagram_maker_get_feature_order_at_pos ( &((*this_).painter),
     125              :                                                               feature_ptr,
     126              :                                                               (double) x,
     127              :                                                               (double) y,
     128              :                                                               &result
     129              :                                                             );
     130              : 
     131            0 :     switch ( pen_err )
     132              :     {
     133            0 :         case PENCIL_ERROR_NONE:
     134              :         {
     135              :             /* success */
     136              :         }
     137            0 :         break;
     138            0 :         case PENCIL_ERROR_OUT_OF_BOUNDS:
     139              :         {
     140            0 :             U8_TRACE_INFO( "PENCIL_ERROR_OUT_OF_BOUNDS in gui_sketch_card_get_feature_order_at_pos" );
     141              :         }
     142            0 :         break;
     143            0 :         case PENCIL_ERROR_UNKNOWN_OBJECT:
     144              :         {
     145            0 :             U8_LOG_ANOMALY( "PENCIL_ERROR_UNKNOWN_OBJECT in gui_sketch_card_get_feature_order_at_pos" );
     146              :         }
     147            0 :         break;
     148              :     }
     149              : 
     150            0 :     return layout_order_get_first( &result );
     151              : }
     152              : 
     153            0 : static inline void gui_sketch_card_get_grid_area ( const gui_sketch_card_t *this_,
     154              :                                                    shape_int_rectangle_t *out_bounds,
     155              :                                                    uint32_t *out_x_count,
     156              :                                                    uint32_t *out_y_count
     157              :                                                  )
     158              : {
     159            0 :     assert( out_bounds != NULL );
     160            0 :     assert( out_x_count != NULL );
     161            0 :     assert( out_y_count != NULL );
     162              : 
     163              :     double x0,y0,dx,dy;
     164              : 
     165            0 :     const geometry_grid_t *grid = pencil_diagram_maker_get_grid_const( &((*this_).painter) );
     166            0 :     const geometry_non_linear_scale_t *const x_scale = geometry_grid_get_x_scale_const( grid );
     167            0 :     const geometry_non_linear_scale_t *const y_scale = geometry_grid_get_y_scale_const( grid );
     168              : 
     169            0 :     x0 = geometry_non_linear_scale_get_location( x_scale, /*order=*/ INT32_MIN );
     170            0 :     dx = geometry_non_linear_scale_get_grid_distances( x_scale );
     171            0 :     *out_x_count = geometry_non_linear_scale_get_grid_intervals( x_scale ) + 1;
     172              : 
     173            0 :     y0 = geometry_non_linear_scale_get_location( y_scale, /*order=*/ INT32_MIN );
     174            0 :     dy = geometry_non_linear_scale_get_grid_distances( y_scale );
     175            0 :     *out_y_count = geometry_non_linear_scale_get_grid_intervals( y_scale ) + 1;
     176              : 
     177            0 :     shape_int_rectangle_init( out_bounds,
     178              :                               (int32_t) x0,
     179              :                               (int32_t) y0,
     180            0 :                               (uint32_t) ((*out_x_count>2) ? ((*out_x_count-1)*dx) : dx),
     181            0 :                               (uint32_t) ((*out_y_count>2) ? ((*out_y_count-1)*dy) : dy)
     182              :                             );
     183            0 : }
     184              : 
     185            0 : static inline const geometry_grid_t *gui_sketch_card_get_grid_const ( const gui_sketch_card_t *this_ )
     186              : {
     187            0 :     return pencil_diagram_maker_get_grid_const( &((*this_).painter) );
     188              : }
     189              : 
     190            0 : static inline bool gui_sketch_card_needs_layout( const gui_sketch_card_t *this_ )
     191              : {
     192            0 :     return (*this_).dirty_elements_layout;
     193              : }
     194              : 
     195            0 : static inline void gui_sketch_card_layout_elements( gui_sketch_card_t *this_, cairo_t *cr )
     196              : {
     197            0 :     pencil_diagram_maker_layout_elements ( &((*this_).painter), NULL, cr );
     198            0 :     (*this_).dirty_elements_layout = false;
     199            0 : }
     200              : 
     201            0 : static inline void gui_sketch_card_do_layout( gui_sketch_card_t *this_, cairo_t *cr )
     202              : {
     203            0 :     if ( gui_sketch_card_is_valid( this_ ) )
     204              :     {
     205              :         /* layout loaded classifiers */
     206            0 :         const int32_t left = shape_int_rectangle_get_left( &((*this_).bounds) );
     207            0 :         const int32_t top = shape_int_rectangle_get_top( &((*this_).bounds) );
     208            0 :         const uint32_t width = shape_int_rectangle_get_width( &((*this_).bounds) );
     209            0 :         const uint32_t height = shape_int_rectangle_get_height( &((*this_).bounds) );
     210              : 
     211              :         geometry_rectangle_t destination;
     212            0 :         geometry_rectangle_init( &destination, left, top, width, height );
     213              : 
     214            0 :         pencil_diagram_maker_define_grid ( &((*this_).painter), destination, cr );
     215            0 :         pencil_diagram_maker_layout_elements ( &((*this_).painter), NULL, cr );
     216            0 :         (*this_).dirty_elements_layout = false;
     217              : 
     218            0 :         geometry_rectangle_destroy( &destination );
     219              :     }
     220              :     else
     221              :     {
     222            0 :         U8_TRACE_INFO( "gui_sketch_card_do_layout called on invalid card." );
     223              :     }
     224            0 : }
     225              : 
     226            0 : static inline const layout_visible_set_t * gui_sketch_card_get_visible_set( const gui_sketch_card_t *this_ )
     227              : {
     228            0 :     return pencil_diagram_maker_get_layout_data_const( &((*this_).painter) );
     229              : }
     230              : 
     231            0 : static inline int32_t gui_sketch_card_get_highest_rel_list_order( const gui_sketch_card_t *this_ )
     232              : {
     233            0 :     int32_t result = 0;
     234              : 
     235            0 :     if ( data_visible_set_is_valid( &((*this_).painter_input_data) ) )
     236              :     {
     237            0 :         for ( uint32_t rs_idx = 0; rs_idx < data_visible_set_get_relationship_count( &((*this_).painter_input_data) ); rs_idx ++ )
     238              :         {
     239              :             const data_relationship_t *relation;
     240            0 :             relation = data_visible_set_get_relationship_const ( &((*this_).painter_input_data), rs_idx );
     241            0 :             if ( data_relationship_get_list_order( relation ) > result )
     242              :             {
     243            0 :                 result = data_relationship_get_list_order( relation );
     244              :             }
     245              :         }
     246              :     }
     247              : 
     248            0 :     return result;
     249              : }
     250              : 
     251            0 : static inline int32_t gui_sketch_card_get_highest_feat_list_order( const gui_sketch_card_t *this_, data_id_t classifier_id )
     252              : {
     253            0 :     int32_t result = 0;
     254              : 
     255            0 :     if ( data_visible_set_is_valid( &((*this_).painter_input_data) ) )
     256              :     {
     257            0 :         for ( uint32_t f_idx = 0; f_idx < data_visible_set_get_feature_count( &((*this_).painter_input_data) ); f_idx ++ )
     258              :         {
     259              :             const data_feature_t *const feat
     260            0 :                 = data_visible_set_get_feature_const ( &((*this_).painter_input_data), f_idx );
     261            0 :             assert( feat != NULL );
     262            0 :             const data_feature_type_t f_type = data_feature_get_main_type( feat );
     263            0 :             if (( f_type == DATA_FEATURE_TYPE_PROPERTY )||( f_type == DATA_FEATURE_TYPE_OPERATION ))
     264              :             {
     265            0 :                 if ( data_feature_get_classifier_row_id( feat ) == data_id_get_row_id( &classifier_id ) )
     266              :                 {
     267            0 :                     if ( data_feature_get_list_order( feat ) > result )
     268              :                     {
     269            0 :                         result = data_feature_get_list_order( feat );
     270              :                     }
     271              :                 }
     272              :             }
     273              :         }
     274              :     }
     275              : 
     276            0 :     return result;
     277              : }
     278              : 
     279              : 
     280              : /*
     281              : Copyright 2016-2025 Andreas Warnke
     282              : 
     283              : Licensed under the Apache License, Version 2.0 (the "License");
     284              : you may not use this file except in compliance with the License.
     285              : You may obtain a copy of the License at
     286              : 
     287              :     http://www.apache.org/licenses/LICENSE-2.0
     288              : 
     289              : Unless required by applicable law or agreed to in writing, software
     290              : distributed under the License is distributed on an "AS IS" BASIS,
     291              : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     292              : See the License for the specific language governing permissions and
     293              : limitations under the License.
     294              : */
        

Generated by: LCOV version 2.0-1