[Bf-blender-cvs] [fc9ec1b9d80] master: Refactor: move Area .blend I/O to blenkernel

Jacques Lucke noreply at git.blender.org
Fri Oct 30 15:29:19 CET 2020


Commit: fc9ec1b9d80fb17d3cc5d3c63f8e4bb356fa7ebc
Author: Jacques Lucke
Date:   Fri Oct 30 15:27:57 2020 +0100
Branches: master
https://developer.blender.org/rBfc9ec1b9d80fb17d3cc5d3c63f8e4bb356fa7ebc

Refactor: move Area .blend I/O to blenkernel

There should be no functional changes.
Eventually, it would be good to handle the different space types
using callbacks.

Ref T76372.

===================================================================

M	source/blender/blenkernel/BKE_screen.h
M	source/blender/blenkernel/intern/screen.c
M	source/blender/blenloader/BLO_read_write.h
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/readfile.h
M	source/blender/blenloader/intern/versioning_250.c
M	source/blender/blenloader/intern/writefile.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_screen.h b/source/blender/blenkernel/BKE_screen.h
index 857d344cf7e..da87ff3e969 100644
--- a/source/blender/blenkernel/BKE_screen.h
+++ b/source/blender/blenkernel/BKE_screen.h
@@ -60,6 +60,7 @@ struct wmWindow;
 struct wmWindowManager;
 struct BlendWriter;
 struct BlendDataReader;
+struct BlendLibReader;
 
 /* spacetype has everything stored to get an editor working, it gets initialized via
  * ED_spacetypes_init() in editors/space_api/spacetypes.c   */
@@ -457,6 +458,14 @@ void BKE_screen_view3d_shading_blend_write(struct BlendWriter *writer,
 void BKE_screen_view3d_shading_blend_read_data(struct BlendDataReader *reader,
                                                struct View3DShading *shading);
 
+void BKE_screen_area_map_blend_write(struct BlendWriter *writer, struct ScrAreaMap *area_map);
+bool BKE_screen_area_map_blend_read_data(struct BlendDataReader *reader,
+                                         struct ScrAreaMap *area_map);
+void BKE_screen_view3d_do_versions_250(struct View3D *v3d, ListBase *regions);
+void BKE_screen_area_blend_read_lib(struct BlendLibReader *reader,
+                                    struct ID *parent_id,
+                                    struct ScrArea *area);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c
index 098dbf6a84e..cfe52dd40e6 100644
--- a/source/blender/blenkernel/intern/screen.c
+++ b/source/blender/blenkernel/intern/screen.c
@@ -21,6 +21,9 @@
  * \ingroup bke
  */
 
+/* Allow using deprecated functionality for .blend file I/O. */
+#define DNA_DEPRECATED_ALLOW
+
 #ifdef WIN32
 #  include "BLI_winstuff.h"
 #endif
@@ -49,6 +52,7 @@
 
 #include "BLT_translation.h"
 
+#include "BKE_gpencil.h"
 #include "BKE_icons.h"
 #include "BKE_idprop.h"
 #include "BKE_idtype.h"
@@ -1128,3 +1132,786 @@ void BKE_screen_view3d_shading_blend_read_data(BlendDataReader *reader, View3DSh
     IDP_BlendDataRead(reader, &shading->prop);
   }
 }
+
+static void write_region(BlendWriter *writer, ARegion *region, int spacetype)
+{
+  BLO_write_struct(writer, ARegion, region);
+
+  if (region->regiondata) {
+    if (region->flag & RGN_FLAG_TEMP_REGIONDATA) {
+      return;
+    }
+
+    switch (spacetype) {
+      case SPACE_VIEW3D:
+        if (region->regiontype == RGN_TYPE_WINDOW) {
+          RegionView3D *rv3d = region->regiondata;
+          BLO_write_struct(writer, RegionView3D, rv3d);
+
+          if (rv3d->localvd) {
+            BLO_write_struct(writer, RegionView3D, rv3d->localvd);
+          }
+          if (rv3d->clipbb) {
+            BLO_write_struct(writer, BoundBox, rv3d->clipbb);
+          }
+        }
+        else {
+          printf("regiondata write missing!\n");
+        }
+        break;
+      default:
+        printf("regiondata write missing!\n");
+    }
+  }
+}
+
+static void write_uilist(BlendWriter *writer, uiList *ui_list)
+{
+  BLO_write_struct(writer, uiList, ui_list);
+
+  if (ui_list->properties) {
+    IDP_BlendWrite(writer, ui_list->properties);
+  }
+}
+
+static void write_space_outliner(BlendWriter *writer, SpaceOutliner *space_outliner)
+{
+  BLI_mempool *ts = space_outliner->treestore;
+
+  if (ts) {
+    SpaceOutliner space_outliner_flat = *space_outliner;
+
+    int elems = BLI_mempool_len(ts);
+    /* linearize mempool to array */
+    TreeStoreElem *data = elems ? BLI_mempool_as_arrayN(ts, "TreeStoreElem") : NULL;
+
+    if (data) {
+      /* In this block we use the memory location of the treestore
+       * but _not_ its data, the addresses in this case are UUID's,
+       * since we can't rely on malloc giving us different values each time.
+       */
+      TreeStore ts_flat = {0};
+
+      /* we know the treestore is at least as big as a pointer,
+       * so offsetting works to give us a UUID. */
+      void *data_addr = (void *)POINTER_OFFSET(ts, sizeof(void *));
+
+      ts_flat.usedelem = elems;
+      ts_flat.totelem = elems;
+      ts_flat.data = data_addr;
+
+      BLO_write_struct(writer, SpaceOutliner, space_outliner);
+
+      BLO_write_struct_at_address(writer, TreeStore, ts, &ts_flat);
+      BLO_write_struct_array_at_address(writer, TreeStoreElem, elems, data_addr, data);
+
+      MEM_freeN(data);
+    }
+    else {
+      space_outliner_flat.treestore = NULL;
+      BLO_write_struct_at_address(writer, SpaceOutliner, space_outliner, &space_outliner_flat);
+    }
+  }
+  else {
+    BLO_write_struct(writer, SpaceOutliner, space_outliner);
+  }
+}
+
+static void write_panel_list(BlendWriter *writer, ListBase *lb)
+{
+  LISTBASE_FOREACH (Panel *, panel, lb) {
+    BLO_write_struct(writer, Panel, panel);
+    write_panel_list(writer, &panel->children);
+  }
+}
+
+static void write_area_regions(BlendWriter *writer, ScrArea *area)
+{
+  LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
+    write_region(writer, region, area->spacetype);
+    write_panel_list(writer, &region->panels);
+
+    LISTBASE_FOREACH (PanelCategoryStack *, pc_act, &region->panels_category_active) {
+      BLO_write_struct(writer, PanelCategoryStack, pc_act);
+    }
+
+    LISTBASE_FOREACH (uiList *, ui_list, &region->ui_lists) {
+      write_uilist(writer, ui_list);
+    }
+
+    LISTBASE_FOREACH (uiPreview *, ui_preview, &region->ui_previews) {
+      BLO_write_struct(writer, uiPreview, ui_preview);
+    }
+  }
+
+  LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
+    LISTBASE_FOREACH (ARegion *, region, &sl->regionbase) {
+      write_region(writer, region, sl->spacetype);
+    }
+
+    if (sl->spacetype == SPACE_VIEW3D) {
+      View3D *v3d = (View3D *)sl;
+      BLO_write_struct(writer, View3D, v3d);
+
+      if (v3d->localvd) {
+        BLO_write_struct(writer, View3D, v3d->localvd);
+      }
+
+      BKE_screen_view3d_shading_blend_write(writer, &v3d->shading);
+    }
+    else if (sl->spacetype == SPACE_GRAPH) {
+      SpaceGraph *sipo = (SpaceGraph *)sl;
+      ListBase tmpGhosts = sipo->runtime.ghost_curves;
+
+      /* temporarily disable ghost curves when saving */
+      BLI_listbase_clear(&sipo->runtime.ghost_curves);
+
+      BLO_write_struct(writer, SpaceGraph, sl);
+      if (sipo->ads) {
+        BLO_write_struct(writer, bDopeSheet, sipo->ads);
+      }
+
+      /* reenable ghost curves */
+      sipo->runtime.ghost_curves = tmpGhosts;
+    }
+    else if (sl->spacetype == SPACE_PROPERTIES) {
+      BLO_write_struct(writer, SpaceProperties, sl);
+    }
+    else if (sl->spacetype == SPACE_FILE) {
+      SpaceFile *sfile = (SpaceFile *)sl;
+
+      BLO_write_struct(writer, SpaceFile, sl);
+      if (sfile->params) {
+        BLO_write_struct(writer, FileSelectParams, sfile->params);
+      }
+    }
+    else if (sl->spacetype == SPACE_SEQ) {
+      BLO_write_struct(writer, SpaceSeq, sl);
+    }
+    else if (sl->spacetype == SPACE_OUTLINER) {
+      SpaceOutliner *space_outliner = (SpaceOutliner *)sl;
+      write_space_outliner(writer, space_outliner);
+    }
+    else if (sl->spacetype == SPACE_IMAGE) {
+      BLO_write_struct(writer, SpaceImage, sl);
+    }
+    else if (sl->spacetype == SPACE_TEXT) {
+      BLO_write_struct(writer, SpaceText, sl);
+    }
+    else if (sl->spacetype == SPACE_SCRIPT) {
+      SpaceScript *scr = (SpaceScript *)sl;
+      scr->but_refs = NULL;
+      BLO_write_struct(writer, SpaceScript, sl);
+    }
+    else if (sl->spacetype == SPACE_ACTION) {
+      BLO_write_struct(writer, SpaceAction, sl);
+    }
+    else if (sl->spacetype == SPACE_NLA) {
+      SpaceNla *snla = (SpaceNla *)sl;
+
+      BLO_write_struct(writer, SpaceNla, snla);
+      if (snla->ads) {
+        BLO_write_struct(writer, bDopeSheet, snla->ads);
+      }
+    }
+    else if (sl->spacetype == SPACE_NODE) {
+      SpaceNode *snode = (SpaceNode *)sl;
+      BLO_write_struct(writer, SpaceNode, snode);
+
+      LISTBASE_FOREACH (bNodeTreePath *, path, &snode->treepath) {
+        BLO_write_struct(writer, bNodeTreePath, path);
+      }
+    }
+    else if (sl->spacetype == SPACE_CONSOLE) {
+      SpaceConsole *con = (SpaceConsole *)sl;
+
+      LISTBASE_FOREACH (ConsoleLine *, cl, &con->history) {
+        /* 'len_alloc' is invalid on write, set from 'len' on read */
+        BLO_write_struct(writer, ConsoleLine, cl);
+        BLO_write_raw(writer, (size_t)cl->len + 1, cl->line);
+      }
+      BLO_write_struct(writer, SpaceConsole, sl);
+    }
+#ifdef WITH_GLOBAL_AREA_WRITING
+    else if (sl->spacetype == SPACE_TOPBAR) {
+      BLO_write_struct(writer, SpaceTopBar, sl);
+    }
+    else if (sl->spacetype == SPACE_STATUSBAR) {
+      BLO_write_struct(writer, SpaceStatusBar, sl);
+    }
+#endif
+    else if (sl->spacetype == SPACE_USERPREF) {
+      BLO_write_struct(writer, SpaceUserPref, sl);
+    }
+    else if (sl->spacetype == SPACE_CLIP) {
+      BLO_write_struct(writer, SpaceClip, sl);
+    }
+    else if (sl->spacetype == SPACE_INFO) {
+      BLO_write_struct(writer, SpaceInfo, sl);
+    }
+  }
+}
+
+void BKE_screen_area_map_blend_write(BlendWriter *writer, ScrAreaMap *area_map)
+{
+  BLO_write_struct_list(writer, ScrVert, &area_map->vertbase);
+  BLO_write_struct_list(writer, ScrEdge, &area_map->edgebase);
+  LISTBASE_FOREACH (ScrArea *, area, &area_map->areabase) {
+    area->butspacetype = area->spacetype; /* Just for compatibility, will be reset below. */
+
+    BLO_write_struct(writer, ScrArea, area);
+
+#ifdef WITH_GLOBAL_AREA_WRITING
+    BLO_write_struct(writer, ScrGlobalAreaData, area->global);
+#endif
+
+    write_area_regions(writer, area);
+
+    area->butspacetype = SPACE_EMPTY; /* Unset again, was changed above. */
+  }
+}
+
+static void direct_link_panel_list(BlendDataReader *reader, ListBase *lb)
+{
+  BLO_read_list(reader, lb);
+
+  LISTBASE_FOREACH (Panel *, panel, lb) {
+    panel->runtime_flag = 0;
+    panel->activedata = NULL;
+    panel->type = NULL;
+    panel->runtime.custom_data_ptr = NULL;
+    direct_link_panel_list(reader, &panel->children);
+  }
+}
+
+static void direct_link_region(BlendDataReader *reader, ARegion *region, int spacetype)
+{
+  direct_link_panel_list(reader, &region->panels);
+
+  BLO_read_list(reader, &region->panels_category_active);
+
+  BLO_read_list(reader, &region->ui_lists);
+


@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list