Blender  V3.3
deg_builder_stack.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2022 Blender Foundation. All rights reserved. */
3 
9 
10 #include <iomanip>
11 #include <ios>
12 #include <iostream>
13 
14 #include "BKE_idtype.h"
15 
16 #include "DNA_ID.h"
17 #include "DNA_action_types.h"
18 #include "DNA_constraint_types.h"
19 #include "DNA_modifier_types.h"
20 
21 namespace blender::deg {
22 
23 /* Spacing between adjacent columns, in number of spaces. */
24 constexpr int kColumnSpacing = 4;
25 
26 /* Width of table columns including column padding.
27  * The type column width is a guesstimate based on "Particle Settings" with some extra padding. */
28 constexpr int kPrintDepthWidth = 5 + kColumnSpacing;
29 constexpr int kPrintTypeWidth = 21 + kColumnSpacing;
30 
31 namespace {
32 
33 /* NOTE: Depth column printing is already taken care of. */
34 
35 void print(std::ostream &stream, const ID *id)
36 {
37  const IDTypeInfo *id_type_info = BKE_idtype_get_info_from_id(id);
38  stream << std::setw(kPrintTypeWidth) << id_type_info->name << (id->name + 2) << "\n";
39 }
40 
41 void print(std::ostream &stream, const bConstraint *constraint)
42 {
43  stream << std::setw(kPrintTypeWidth) << ("Constraint") << constraint->name << "\n";
44 }
45 
46 void print(std::ostream &stream, const ModifierData *modifier_data)
47 {
48  stream << std::setw(kPrintTypeWidth) << ("Modifier") << modifier_data->name << "\n";
49 }
50 
51 void print(std::ostream &stream, const bPoseChannel *pchan)
52 {
53  stream << std::setw(kPrintTypeWidth) << ("Pose Channel") << pchan->name << "\n";
54 }
55 
56 } // namespace
57 
58 void BuilderStack::print_backtrace(std::ostream &stream)
59 {
60  const std::ios_base::fmtflags old_flags(stream.flags());
61 
62  stream << std::left;
63 
64  stream << std::setw(kPrintDepthWidth) << "Depth" << std::setw(kPrintTypeWidth) << "Type"
65  << "Name"
66  << "\n";
67 
68  stream << std::setw(kPrintDepthWidth) << "-----" << std::setw(kPrintTypeWidth) << "----"
69  << "----"
70  << "\n";
71 
72  int depth = 1;
73  for (const Entry &entry : stack_) {
74  stream << std::setw(kPrintDepthWidth) << depth;
75  ++depth;
76 
77  if (entry.id_ != nullptr) {
78  print(stream, entry.id_);
79  }
80  else if (entry.constraint_ != nullptr) {
81  print(stream, entry.constraint_);
82  }
83  else if (entry.modifier_data_ != nullptr) {
84  print(stream, entry.modifier_data_);
85  }
86  else if (entry.pchan_ != nullptr) {
87  print(stream, entry.pchan_);
88  }
89  }
90 
91  stream.flags(old_flags);
92 }
93 
94 } // namespace blender::deg
const struct IDTypeInfo * BKE_idtype_get_info_from_id(const struct ID *id)
ID and Library types, which are fundamental for sdna.
void print_backtrace(std::ostream &stream)
static int left
constexpr int kColumnSpacing
constexpr int kPrintTypeWidth
constexpr int kPrintDepthWidth
const char * name
Definition: BKE_idtype.h:132
Definition: DNA_ID.h:368