Skip to content

DDeiAbstractShape

  DDeiAbstractShape代表是所有可见图形的父类,定义了图形所需要的公共属性和方法。   DDeiAbstractShape实例包含了一个图形的所有数据和渲染器,在获取后可以通过它访问其他内容。DDeiAbstractShape中的layer指向所在图层,stage指向所属舞台,pModel指向其父容器,顶级指向layer

  本篇最后提供的示例可以在文档中直接预览。

属性

属性名说明数据类型静态默认值备注
id图形IDstring画布唯一
unicode唯一编号string系统生成自动编码
code编码string一般用于业务
text文本string
poly坐标策略number11直角坐标/2极坐标
rotate旋转量number1.0只读
cpv中心点向量object(0,0,0)中心点坐标
hpv平行拉伸向量objec[]用于计算旋转/拉伸量
pvs点向量object[]构成图形的所有点
essBounds实际大小object未经旋转、缩放的实际大小
text文本string显示文本
sptStyle特殊文本样式object[]
zIndex图层层次number影响渲染顺序
state背景DDeiEnumControlStateDEFAULT
stage所属舞台DDeiStage
layer所属图层DDeiLayer
pModel所属容器DDeiContainer
modelCode模型的编码string区分modelType相同,但业务含义不同的模型
modelType模型类型stringAbstractShape
border边框object
border.type边框类型number0无/1实线
border.color边框颜色string
border.opacity透明度number0-1之间1
border.width宽度number>01
border.dash线段样式Array>0
border.roung圆角number0-100
fill填充object
fill.type填充类型number0无/1纯色/2图片
fill.color填充颜色string
fill.image填充图片stringurl/base64
fill.opacity透明度number0-1之间1
font字体object
font.family字体名称string系统默认
font.color字体颜色stringblack
font.size字体大小string14
textStyle文本样式object
textStyle.align横向对齐number1左/2中/3右2
textStyle.valign纵向对齐number1上/2中/3下2
textStyle.feed自动换行number1是/0否1
textStyle.scale超范围策略number0隐藏/1省略/2缩小/3扩展0文本超出控件大小时的策略
textStyle.lockWidth锁定宽度number0否/1是0超范围自动扩展的情况下锁定宽度
textStyle.hollow镂空number0否/1是0
textStyle.bold加粗number0否/1是0
textStyle.italic斜体number0否/1是0
textStyle.underline下划线number0否/1是0
textStyle.deleteline删除线number0否/1是0
textStyle.bgcolor文本背景string
textStyle.hspace水平间距number0-100.5
textStyle.vspace垂直间距number0-100.5

方法

static initByJSON

  根据JSON,创建一个DDeiAbstractShape实例(实际为子类实例)

参数

参数名类型范围默认值备注
jsonobject文件JSON数据
tempDataobject用于初始化的数据:{currentContainer:当前容器实例,currentStage:当前stage实例,currentLayer:当前layer实例}
initPVSbooleantrue是否初始化点向量

返回值

类型备注
DDeiAbstractShapeDDeiAbstractShape实例(实际为子类实例)

static loadFromJSON

  将JSON转换为一个DDeiAbstractShape实例(实际为子类实例)

参数

参数名类型范围默认值备注
jsonobject文件JSON数据
tempDataobject用于初始化的数据:{currentContainer:当前容器实例,currentStage:当前stage实例,currentLayer:当前layer实例}

返回值

类型备注
DDeiAbstractShapeDDeiAbstractShape实例(实际为子类实例)

toJSON

  将图形实例转换为JSON对象

参数

  无

返回值

类型备注
JSON包含了DDeiAbstractShape实例(实际为子类实例)所有信息的JSON对象

initRender

  初始化渲染器,并绑定

参数

  无

返回值

  无

initPVS

  初始化向量,基于width和height构建向量,默认中心点在0,0的位置

参数

  无

返回值

  无

executeSample

  执行采样,根据配置获取构成图形的向量点

参数

  无

返回值

  无

syncVectors

  同步一个图形的向量到当前图形

参数

参数名类型范围默认值备注
sourceDDeiAbstractShape
clonePVbooleanfalse是否采用克隆的方式同步

返回值

  无

transVectors

  对当前图形执行向量变换

参数

参数名类型范围默认值备注
matrixMatrix33维变换矩阵
paramsobject特殊配置

返回值

  无

setSptStyle

  设置特殊文本样式

WARNING

在手工设置text后需要手动维护关系

参数

参数名类型范围默认值备注
sIdxnumber开始下标
eIdxnumber结束下标
pathsstring[]/string属性路径
valueany
emptyDeletebooleantrue清楚空值

返回值

  无

getSptStyle

  获取特殊文本样式

WARNING

在手工设置text后需要手动维护关系

参数

参数名类型范围默认值备注
sIdxnumber开始下标
eIdxnumber结束下标
pathsstring[]/string属性路径

返回值

类型备注
JSON[]开始和结束下标之间所有设置的特殊样式

getSptAllStyles

  获取特殊文本样式

WARNING

在手工设置text后需要手动维护关系

参数

参数名类型范围默认值备注
sIdxnumber开始下标
eIdxnumber结束下标

返回值

类型备注
JSON[]开始和结束下标之间所有设置的特殊样式

clearSptStyle

  清空特殊文本样式

参数

  无

返回值

  无

setPosition

  设置坐标位置

参数

参数名类型范围默认值备注
pointjson{x:0,y:0}位置
coordnumber21标尺坐标/2页面坐标
unitstringmm/cm/px/inch/m单位
typenumber21圆心/2左上角

返回值

  无

getPosition

  获取坐标位置

参数

参数名类型范围默认值备注
coordnumber21标尺坐标/2页面坐标
unitstringmm/cm/px/inch/m单位
typenumber21圆心/2左上角

返回值

类型备注
point单位下的坐标点

setRotate

  设置旋转角度

参数

参数名类型范围默认值备注
rotatenumber00-360

返回值

  无

getProjPointOnLine

  得到点在图形某条线上的投射点

参数

参数名类型范围默认值备注
pointobject测试点
distanceobject内外部判定区间的距离
directnumber1方向,1外部,2内部
indexnumber线开始点向量的下标

返回值

  无

notifyChange

  通知改变,刷新画布

参数

  无

返回值

  无

示例

代码

vue
<script setup lang="ts">
import DDeiEditorView from "ddei-editor";
import {DDeiEditor,DDeiStage,DDeiLayer,DDeiCoreStandLayout,DDeiAbstractShape} from "ddei-editor";
import { defineComponent, markRaw,getCurrentInstance,ref } from "vue";
//获取主对象实例,代替this获取$refs
const {proxy} = getCurrentInstance()

const rotateVal = ref(0);

const options = markRaw({
  config: { 
    "grid": 0, //网格线
    "background": { color: "blue", opacity: 0.1 }, //背景色
    initData: {
      controls: [
        {
          id:"shape_1",
          model: "102010",
          text: "初始化图形"
        },
      ]
    }
  },
  //配置扩展插件
  extensions: [
    //布局的配置
    DDeiCoreStandLayout.configuration({
      //配置插件
      'top': [],
      'middle': ['ddei-core-panel-canvasview'],
      'bottom': [],
      'left': [],
      'right': []
    }),
  ],
})

const rotate = () => {
  //获取编辑器 
  let editor = proxy.$refs["ddei_editor_api_5"].editor;
  //添加控件
  let model:DDeiAbstractShape = editor.getControlById("shape_1");
  rotateVal.value += 15;
  model.setRotate(rotateVal.value);
  model.notifyChange()
  
};
const scaleAdd = () => {
  //获取编辑器 
  let editor = proxy.$refs["ddei_editor_api_5"].editor;
  //添加控件
  let model:DDeiAbstractShape = editor.getControlById("shape_1");
  model.scale(1.1,1.1);
  model.notifyChange()
};

const scaleDiv = () => {
  //获取编辑器 
  let editor = proxy.$refs["ddei_editor_api_5"].editor;
  //添加控件
  let model:DDeiAbstractShape = editor.getControlById("shape_1");
  model.scale(0.9,0.9);
  model.notifyChange()
};

const changeText = () => {
  //获取编辑器 
  let editor = proxy.$refs["ddei_editor_api_5"].editor;
  //添加控件
  let model:DDeiAbstractShape = editor.getControlById("shape_1");
  model.text += "-改"
  model.notifyChange()
};

const changeColor = () => {
  //获取编辑器 
  let editor = proxy.$refs["ddei_editor_api_5"].editor;
  //添加控件
  let model:DDeiAbstractShape = editor.getControlById("shape_1");
  model.font = {color : "red"}
  model.notifyChange()
};

const moveControl = () => {
  //获取编辑器 
  let editor = proxy.$refs["ddei_editor_api_5"].editor;
  //添加控件
  let model:DDeiAbstractShape = editor.getControlById("shape_1");
  //获取坐标,单位(英寸)
  let incPos = model.getPosition(1,'inch');
  incPos.x += 0.1;
  incPos.y += 0.1;
  //设置坐标,单位(英寸)
  model.setPosition(incPos,1,'inch');
  model.text = incPos.x.toFixed(1)+" ,"+incPos.y.toFixed(1)+" 英寸"
  model.notifyChange()
};



</script>

<template>

<button @click="rotate" style="border:1px solid grey;margin-left:5px;padding:5px">旋转</button>
<button @click="scaleAdd" style="border:1px solid grey;margin-left:5px;padding:5px">放大</button>
<button @click="scaleDiv" style="border:1px solid grey;margin-left:5px;padding:5px">缩小</button>
<button @click="changeText" style="border:1px solid grey;margin-left:5px;padding:5px">修改文本</button>
<button @click="changeColor" style="border:1px solid grey;margin-left:5px;padding:5px">变色</button>
<button @click="moveControl" style="border:1px solid grey;margin-left:5px;padding:5px">移动</button>
<DDeiEditorView :options="options" ref="ddei_editor_api_5" id="ddei_editor_api_5"></DDeiEditorView>

效果预览

技术支持