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.65.6_covts Lines: 0 96 0.0 %
Date: 2025-09-25 21:07:53 Functions: 0 18 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 :     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 const geometry_grid_t *gui_sketch_card_get_grid_const ( const gui_sketch_card_t *this_ )
     154             : {
     155           0 :     return pencil_diagram_maker_get_grid_const( &((*this_).painter) );
     156             : }
     157             : 
     158           0 : static inline bool gui_sketch_card_needs_layout( const gui_sketch_card_t *this_ )
     159             : {
     160           0 :     return (*this_).dirty_elements_layout;
     161             : }
     162             : 
     163           0 : static inline void gui_sketch_card_layout_elements( gui_sketch_card_t *this_, cairo_t *cr )
     164             : {
     165           0 :     pencil_diagram_maker_layout_elements ( &((*this_).painter), NULL, cr );
     166           0 :     (*this_).dirty_elements_layout = false;
     167           0 : }
     168             : 
     169           0 : static inline void gui_sketch_card_do_layout( gui_sketch_card_t *this_, cairo_t *cr )
     170             : {
     171           0 :     if ( gui_sketch_card_is_valid( this_ ) )
     172             :     {
     173             :         /* layout loaded classifiers */
     174           0 :         const int32_t left = shape_int_rectangle_get_left( &((*this_).bounds) );
     175           0 :         const int32_t top = shape_int_rectangle_get_top( &((*this_).bounds) );
     176           0 :         const uint32_t width = shape_int_rectangle_get_width( &((*this_).bounds) );
     177           0 :         const uint32_t height = shape_int_rectangle_get_height( &((*this_).bounds) );
     178             : 
     179             :         geometry_rectangle_t destination;
     180           0 :         geometry_rectangle_init( &destination, left, top, width, height );
     181             : 
     182           0 :         pencil_diagram_maker_define_grid ( &((*this_).painter), destination, cr );
     183           0 :         pencil_diagram_maker_layout_elements ( &((*this_).painter), NULL, cr );
     184           0 :         (*this_).dirty_elements_layout = false;
     185             : 
     186           0 :         geometry_rectangle_destroy( &destination );
     187             :     }
     188             :     else
     189             :     {
     190           0 :         U8_TRACE_INFO( "gui_sketch_card_do_layout called on invalid card." );
     191             :     }
     192           0 : }
     193             : 
     194           0 : static inline const layout_visible_set_t * gui_sketch_card_get_visible_set( const gui_sketch_card_t *this_ )
     195             : {
     196           0 :     return pencil_diagram_maker_get_layout_data_const( &((*this_).painter) );
     197             : }
     198             : 
     199           0 : static inline int32_t gui_sketch_card_get_highest_rel_list_order( const gui_sketch_card_t *this_ )
     200             : {
     201           0 :     int32_t result = 0;
     202             : 
     203           0 :     if ( data_visible_set_is_valid( &((*this_).painter_input_data) ) )
     204             :     {
     205           0 :         for ( uint32_t rs_idx = 0; rs_idx < data_visible_set_get_relationship_count( &((*this_).painter_input_data) ); rs_idx ++ )
     206             :         {
     207             :             const data_relationship_t *relation;
     208           0 :             relation = data_visible_set_get_relationship_const ( &((*this_).painter_input_data), rs_idx );
     209           0 :             if ( data_relationship_get_list_order( relation ) > result )
     210             :             {
     211           0 :                 result = data_relationship_get_list_order( relation );
     212             :             }
     213             :         }
     214             :     }
     215             : 
     216           0 :     return result;
     217             : }
     218             : 
     219           0 : static inline int32_t gui_sketch_card_get_highest_feat_list_order( const gui_sketch_card_t *this_, data_id_t classifier_id )
     220             : {
     221           0 :     int32_t result = 0;
     222             : 
     223           0 :     if ( data_visible_set_is_valid( &((*this_).painter_input_data) ) )
     224             :     {
     225           0 :         for ( uint32_t f_idx = 0; f_idx < data_visible_set_get_feature_count( &((*this_).painter_input_data) ); f_idx ++ )
     226             :         {
     227             :             const data_feature_t *const feat
     228           0 :                 = data_visible_set_get_feature_const ( &((*this_).painter_input_data), f_idx );
     229           0 :             assert( feat != NULL );
     230           0 :             const data_feature_type_t f_type = data_feature_get_main_type( feat );
     231           0 :             if (( f_type == DATA_FEATURE_TYPE_PROPERTY )||( f_type == DATA_FEATURE_TYPE_OPERATION ))
     232             :             {
     233           0 :                 if ( data_feature_get_classifier_row_id( feat ) == data_id_get_row_id( &classifier_id ) )
     234             :                 {
     235           0 :                     if ( data_feature_get_list_order( feat ) > result )
     236             :                     {
     237           0 :                         result = data_feature_get_list_order( feat );
     238             :                     }
     239             :                 }
     240             :             }
     241             :         }
     242             :     }
     243             : 
     244           0 :     return result;
     245             : }
     246             : 
     247             : 
     248             : /*
     249             : Copyright 2016-2025 Andreas Warnke
     250             : 
     251             : Licensed under the Apache License, Version 2.0 (the "License");
     252             : you may not use this file except in compliance with the License.
     253             : You may obtain a copy of the License at
     254             : 
     255             :     http://www.apache.org/licenses/LICENSE-2.0
     256             : 
     257             : Unless required by applicable law or agreed to in writing, software
     258             : distributed under the License is distributed on an "AS IS" BASIS,
     259             : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     260             : See the License for the specific language governing permissions and
     261             : limitations under the License.
     262             : */

Generated by: LCOV version 1.16