Skip to main content

DataModel

Struct DataModel 

Source
pub struct DataModel {
    pub points: Vec<DataModelPoint>,
    pub connections: Vec<DataModelConnection>,
}
Expand description

SmartArt 数据模型(data part 的结构化表达)。

对应 /ppt/diagrams/dataN.xml<dgm:dataModel> 根元素。 一个 SmartArt 图形的所有节点(pt)与连接(cxn)都在这里—— 这是 SmartArt 的核心数据,编辑/查询节点都基于此结构。

§结构示例

<dgm:dataModel xmlns:dgm="..." xmlns:a="...">
  <dgm:ptLst>
    <dgm:pt modelId="0" type="doc"/>
    <dgm:pt modelId="1" type="par">
      <dgm:prSet ang="0"/>
      <dgm:spPr/>
      <dgm:t><a:bodyPr/><a:lstStyle/><a:p><a:r><a:t>根节点</a:t></a:r></a:p></dgm:t>
    </dgm:pt>
  </dgm:ptLst>
  <dgm:cxnLst>
    <dgm:cxn type="parChld" srcId="1" destId="2"/>
  </dgm:cxnLst>
</dgm:dataModel>

Fields§

§points: Vec<DataModelPoint>

节点列表(<dgm:ptLst>/<dgm:pt>)。

§connections: Vec<DataModelConnection>

连接列表(<dgm:cxnLst>/<dgm:cxn>)。

Implementations§

Source§

impl DataModel

Source

pub fn parse_from_xml(xml: &str) -> Result<DataModel>

<dgm:dataModel> XML 字符串解析为强类型 DataModel

§参数
  • xml:完整 dataN.xml 内容(含 <?xml?> 声明与 <dgm:dataModel> 根元素)。
§返回值
  • 成功:返回 DataModel,包含所有节点与连接。
  • 失败:返回 Error::Xml,包含解析错误上下文。
§解析策略

使用 quick-xml SAX 事件流解析:

  • 进入 <dgm:pt> 时收集属性(modelId / type),开始累积 raw_xml;
  • <dgm:pt> 内的 <a:t> 文本事件提取节点文本;
  • 离开 <dgm:pt> 时把累积的 raw_xml 切片写入 point.raw_xml
  • <dgm:cxn> 类似处理。
§错误
  • Error::Xml:XML 解析失败(畸形 / 未闭合等)。
Source

pub fn to_xml(&self) -> String

DataModel 序列化为 <dgm:dataModel> XML 字符串。

注意:本方法用于“从结构化模型重建 XML“场景;如果只是 round-trip, 应直接使用 crate::presentation::DiagramEntry 持有的 data_xml 字段。

§输出结构
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<dgm:dataModel xmlns:dgm="..." xmlns:a="...">
  <dgm:ptLst>
    <!-- 每个 point 的 raw_xml 直接透传(保留 byte-exact) -->
  </dgm:ptLst>
  <dgm:cxnLst>
    <!-- 每个 connection 的 raw_xml 直接透传 -->
  </dgm:cxnLst>
</dgm:dataModel>
§设计要点

节点/连接的子元素(<dgm:prSet> / <dgm:spPr> / <dgm:t> 等)通过 raw_xml 字段直接透传,避免重新序列化时丢失属性。

§结构化重建分支

raw_xml 为空但 text 字段非空时(用户新建的节点),按 OOXML 顺序 构造完整 <dgm:pt> 结构:

<dgm:pt modelId="..." type="...">
  <dgm:t><a:bodyPr/><a:lstStyle/><a:p><a:r><a:t>文本</a:t></a:r></a:p></dgm:t>
</dgm:pt>

这是为了支持“从零构造 SmartArt 数据模型并写出“的场景。

Source

pub fn point_mut(&mut self, model_id: u32) -> Option<&mut DataModelPoint>

model_id 查找节点,返回可变引用。

便捷方法:避免外部遍历 points 列表。未找到返回 None

Source

pub fn point(&self, model_id: u32) -> Option<&DataModelPoint>

model_id 查找节点,返回不可变引用。

Source

pub fn set_point_text( &mut self, model_id: u32, new_text: impl Into<String>, ) -> bool

设置指定 model_id 节点的显示文本(便捷方法)。

内部调用 DataModelPoint::set_text。未找到节点返回 false, 成功修改返回 true

Trait Implementations§

Source§

impl Clone for DataModel

Source§

fn clone(&self) -> DataModel

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DataModel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for DataModel

Source§

fn default() -> DataModel

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V