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

Generated by: LCOV version 1.16