LCOV - code coverage report
Current view: top level - gui/source/sketch - gui_sketch_card.c (source / functions) Hit Total Coverage
Test: crystal-facet-uml_v1.57.0_covts Lines: 0 125 0.0 %
Date: 2024-04-07 11:14:42 Functions: 0 4 0.0 %

          Line data    Source code
       1             : /* File: gui_sketch_card.c; Copyright and License: see below */
       2             : 
       3             : #include "sketch/gui_sketch_card.h"
       4             : #include "pencil_diagram_maker.h"
       5             : #include "geometry/geometry_rectangle.h"
       6             : #include "u8/u8_trace.h"
       7             : #include "u8/u8_log.h"
       8             : #include <gdk/gdk.h>
       9             : 
      10           0 : void gui_sketch_card_init( gui_sketch_card_t *this_ )
      11             : {
      12           0 :     U8_TRACE_BEGIN();
      13             : 
      14           0 :     (*this_).visible = false;
      15           0 :     (*this_).dirty_elements_layout = false;
      16           0 :     shape_int_rectangle_init( &((*this_).bounds), 0, 0, 0, 0 );
      17           0 :     data_visible_set_init( &((*this_).painter_input_data) );
      18           0 :     data_profile_part_init( &((*this_).profile) );
      19           0 :     pencil_diagram_maker_init( &((*this_).painter), &((*this_).painter_input_data), &((*this_).profile) );
      20           0 :     gui_sketch_marker_init( &((*this_).sketch_marker), false );
      21             : 
      22           0 :     U8_TRACE_END();
      23           0 : }
      24             : 
      25           0 : void gui_sketch_card_destroy( gui_sketch_card_t *this_ )
      26             : {
      27           0 :     U8_TRACE_BEGIN();
      28             : 
      29           0 :     gui_sketch_marker_destroy( &((*this_).sketch_marker) );
      30           0 :     pencil_diagram_maker_destroy( &((*this_).painter) );
      31           0 :     data_profile_part_destroy( &((*this_).profile) );
      32           0 :     data_visible_set_destroy( &((*this_).painter_input_data) );
      33           0 :     shape_int_rectangle_destroy(&((*this_).bounds));
      34             : 
      35           0 :     U8_TRACE_END();
      36           0 : }
      37             : 
      38             : static const double WHITE_R = 1.0;
      39             : static const double WHITE_G = 1.0;
      40             : static const double WHITE_B = 1.0;
      41             : static const double WHITE_A = 1.0;
      42             : 
      43           0 : void gui_sketch_card_draw ( gui_sketch_card_t *this_, gui_marked_set_t *marker, cairo_t *cr )
      44             : {
      45           0 :     U8_TRACE_BEGIN();
      46           0 :     assert( NULL != cr );
      47             : 
      48           0 :     if ( (*this_).visible )
      49             :     {
      50           0 :         const int32_t left = shape_int_rectangle_get_left( &((*this_).bounds) );
      51           0 :         const int32_t top = shape_int_rectangle_get_top( &((*this_).bounds) );
      52           0 :         const uint32_t width = shape_int_rectangle_get_width( &((*this_).bounds) );
      53           0 :         const uint32_t height = shape_int_rectangle_get_height( &((*this_).bounds) );
      54             : 
      55             :         /* get marked ids */
      56           0 :         const data_id_t mark_focused = gui_marked_set_get_focused_obj( marker );
      57           0 :         const data_id_t mark_highlighted = gui_marked_set_get_highlighted( marker );
      58           0 :         const data_small_set_t *mark_selected_set = gui_marked_set_get_selected_set_const( marker );
      59             : 
      60             :         /* layout elements if necessary */
      61           0 :         if ( (*this_).dirty_elements_layout )
      62             :         {
      63           0 :             pencil_diagram_maker_layout_elements ( &((*this_).painter), NULL, cr );
      64           0 :             (*this_).dirty_elements_layout = false;
      65             :         }
      66             : 
      67             :         /* draw paper */
      68           0 :         cairo_set_source_rgba( cr, WHITE_R, WHITE_G, WHITE_B, WHITE_A );
      69           0 :         cairo_rectangle ( cr, left, top, width, height );
      70           0 :         cairo_fill (cr);
      71             : 
      72             : #ifndef NDEBUG
      73             :         /* draw warnings at overlaps in debug mode */
      74           0 :         pencil_diagram_maker_show_overlaps ( &((*this_).painter), NULL, cr );
      75             : #endif
      76             : 
      77             :         /* draw highlighting */
      78           0 :         const data_diagram_t *const diag = data_visible_set_get_diagram_const ( &((*this_).painter_input_data) );
      79           0 :         const data_id_t diag_id = data_diagram_get_data_id( diag );
      80           0 :         gui_sketch_marker_prepare_draw( &((*this_).sketch_marker),
      81             :                                         diag_id,
      82             :                                         marker,
      83             :                                         (*this_).bounds,
      84             :                                         cr
      85             :                                       );
      86             : 
      87             :         /* draw the current diagram */
      88           0 :         pencil_diagram_maker_draw ( &((*this_).painter),
      89             :                                     mark_focused,
      90             :                                     mark_highlighted,
      91             :                                     mark_selected_set,
      92             :                                     cr
      93             :                                   );
      94             :     }
      95             : 
      96           0 :     U8_TRACE_END();
      97           0 : }
      98             : 
      99           0 : void gui_sketch_card_move_object_to_order ( gui_sketch_card_t *this_,
     100             :                                             data_id_t obj_id,
     101             :                                             const layout_order_t *order )
     102             : {
     103           0 :     U8_TRACE_BEGIN();
     104           0 :     assert( NULL != order );
     105             : 
     106           0 :     const data_table_t table = data_id_get_table ( &obj_id );
     107           0 :     const data_row_id_t row_id = data_id_get_row_id ( &obj_id );
     108             : 
     109           0 :     layout_order_type_t order_type = layout_order_get_order_type( order );
     110           0 :     switch ( order_type )
     111             :     {
     112           0 :         case PENCIL_LAYOUT_ORDER_TYPE_X_Y:
     113             :         {
     114             :             switch ( table )
     115             :             {
     116           0 :                 case DATA_TABLE_CLASSIFIER:
     117             :                 {
     118           0 :                     const int32_t x_order = layout_order_get_first( order );
     119           0 :                     const int32_t y_order = layout_order_get_second( order );
     120             : 
     121             :                     data_classifier_t *const move_me
     122           0 :                         = data_visible_set_get_classifier_by_id_ptr( &((*this_).painter_input_data), row_id );
     123           0 :                     if ( move_me == NULL )
     124             :                     {
     125           0 :                         U8_LOG_WARNING( "pencil input data does not contain the object to be moved" );
     126           0 :                         data_id_trace( &obj_id );
     127             :                     }
     128             :                     else
     129             :                     {
     130           0 :                         data_classifier_set_x_order( move_me, x_order );
     131           0 :                         data_classifier_set_y_order( move_me, y_order );
     132             : 
     133             :                         /* success */
     134           0 :                         (*this_).dirty_elements_layout = true;
     135             :                     }
     136             :                 }
     137           0 :                 break;
     138             : 
     139           0 :                 case DATA_TABLE_FEATURE:
     140             :                 {
     141           0 :                     U8_LOG_WARNING( "object to be x/y-moved has no x/y coordinates: feature" );
     142             :                 }
     143           0 :                 break;
     144             : 
     145           0 :                 case DATA_TABLE_RELATIONSHIP:
     146             :                 {
     147           0 :                     U8_LOG_WARNING( "object to be x/y-moved has no x/y coordinates: relationship" );
     148             :                 }
     149           0 :                 break;
     150             : 
     151           0 :                 case DATA_TABLE_DIAGRAMELEMENT:
     152             :                 {
     153           0 :                     U8_LOG_WARNING( "not implemented to move diagramelements. use the classifier instead." );
     154             :                 }
     155           0 :                 break;
     156             : 
     157           0 :                 case DATA_TABLE_DIAGRAM:
     158             :                 {
     159             :                     /* pencil cannot move diagrams */
     160           0 :                     U8_LOG_WARNING( "object to be x/y-moved has unexpected type: diagram" );
     161             :                 }
     162           0 :                 break;
     163             : 
     164           0 :                 default:
     165             :                 {
     166           0 :                     U8_LOG_WARNING( "object to be x/y-moved has illegal type" );
     167             :                 }
     168           0 :                 break;
     169             :             }
     170             :         }
     171           0 :         break;
     172             : 
     173           0 :         case PENCIL_LAYOUT_ORDER_TYPE_LIST:
     174             :         {
     175             :             switch ( table )
     176             :             {
     177           0 :                 case DATA_TABLE_CLASSIFIER:
     178             :                 {
     179           0 :                     const int32_t list_order = layout_order_get_first( order );
     180             : 
     181           0 :                     data_classifier_t *const move_me = data_visible_set_get_classifier_by_id_ptr( &((*this_).painter_input_data), row_id );
     182           0 :                     if ( move_me == NULL )
     183             :                     {
     184           0 :                         U8_LOG_WARNING( "pencil input data does not contain the classifier to be moved" );
     185           0 :                         data_id_trace( &obj_id );
     186             :                     }
     187             :                     else
     188             :                     {
     189           0 :                         data_classifier_set_list_order( move_me, list_order );
     190             : 
     191             :                         /* success */
     192           0 :                         (*this_).dirty_elements_layout = true;
     193             :                     }
     194             :                 }
     195           0 :                 break;
     196             : 
     197           0 :                 case DATA_TABLE_FEATURE:
     198             :                 {
     199           0 :                     const int32_t list_order = layout_order_get_first( order );
     200             : 
     201           0 :                     data_feature_t *const move_me = data_visible_set_get_feature_by_id_ptr( &((*this_).painter_input_data), row_id );
     202           0 :                     if ( move_me == NULL )
     203             :                     {
     204           0 :                         U8_LOG_WARNING( "pencil input data does not contain the feature to be moved" );
     205           0 :                         data_id_trace( &obj_id );
     206             :                     }
     207             :                     else
     208             :                     {
     209           0 :                         data_feature_set_list_order( move_me, list_order );
     210             : 
     211             :                         /* success */
     212           0 :                         (*this_).dirty_elements_layout = true;
     213             :                     }
     214             :                 }
     215           0 :                 break;
     216             : 
     217           0 :                 case DATA_TABLE_RELATIONSHIP:
     218             :                 {
     219           0 :                     const int32_t list_order = layout_order_get_first( order );
     220             : 
     221           0 :                     data_relationship_t *const move_me = data_visible_set_get_relationship_by_id_ptr( &((*this_).painter_input_data), row_id );
     222           0 :                     if ( move_me == NULL )
     223             :                     {
     224           0 :                         U8_LOG_WARNING( "pencil input data does not contain the relationship to be moved" );
     225           0 :                         data_id_trace( &obj_id );
     226             :                     }
     227             :                     else
     228             :                     {
     229           0 :                         data_relationship_set_list_order( move_me, list_order );
     230             : 
     231             :                         /* success */
     232           0 :                         (*this_).dirty_elements_layout = true;
     233             :                     }
     234             :                 }
     235           0 :                 break;
     236             : 
     237           0 :                 case DATA_TABLE_DIAGRAMELEMENT:
     238             :                 {
     239           0 :                     U8_LOG_WARNING( "not implemented to move diagramelements. use the classifier instead." );
     240             :                 }
     241           0 :                 break;
     242             : 
     243           0 :                 case DATA_TABLE_DIAGRAM:
     244             :                 {
     245             :                     /* pencil cannot move diagrams */
     246           0 :                     U8_LOG_WARNING( "object to be x/y-moved has unexpected type: diagram" );
     247             :                 }
     248           0 :                 break;
     249             : 
     250           0 :                 default:
     251             :                 {
     252           0 :                     U8_LOG_WARNING( "object to be x/y-moved has illegal type" );
     253             :                 }
     254           0 :                 break;
     255             :             }
     256             :         }
     257           0 :         break;
     258             : 
     259           0 :         case PENCIL_LAYOUT_ORDER_TYPE_NONE:
     260             :         {
     261             :             /* nothing to do */
     262             :             /* no error */
     263           0 :             U8_LOG_ANOMALY( "object to be moved has no movement data" );
     264             :         }
     265           0 :         break;
     266             : 
     267           0 :         case PENCIL_LAYOUT_ORDER_TYPE_OUT_OF_RANGE:
     268             :         default:
     269             :         {
     270           0 :             U8_LOG_WARNING( "object to be x/y-moved has illegal movement data" );
     271             :         }
     272           0 :         break;
     273             :     }
     274             : 
     275           0 :     U8_TRACE_END();
     276           0 : }
     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             : */
     294             : 

Generated by: LCOV version 1.16