电子档案
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

507 lines
13 KiB

  1. /* Licensed under the Apache License, Version 2.0 (the "License");
  2. * you may not use this file except in compliance with the License.
  3. * You may obtain a copy of the License at
  4. *
  5. * http://www.apache.org/licenses/LICENSE-2.0
  6. *
  7. * Unless required by applicable law or agreed to in writing, software
  8. * distributed under the License is distributed on an "AS IS" BASIS,
  9. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. * See the License for the specific language governing permissions and
  11. * limitations under the License.
  12. */
  13. function _cmmnGetColor(element, defaultColor)
  14. {
  15. var strokeColor;
  16. if (element.current) {
  17. strokeColor = CURRENT_COLOR;
  18. } else if (element.completed) {
  19. strokeColor = COMPLETED_COLOR;
  20. } else if (element.available) {
  21. strokeColor = AVAILABLE_COLOR;
  22. } else {
  23. strokeColor = defaultColor;
  24. }
  25. return strokeColor;
  26. }
  27. function _drawPlanModel(planModel)
  28. {
  29. var rect = paper.rect(planModel.x, planModel.y, planModel.width, planModel.height);
  30. rect.attr({"stroke-width": 1,
  31. "stroke": "#000000",
  32. "fill": "white"
  33. });
  34. if (planModel.name)
  35. {
  36. var planModelName = paper.text(planModel.x + 14, planModel.y + (planModel.height / 2), planModel.name).attr({
  37. "text-anchor" : "middle",
  38. "font-family" : "Arial",
  39. "font-size" : "12",
  40. "fill" : "#000000"
  41. });
  42. planModelName.transform("r270");
  43. }
  44. }
  45. function _drawSubProcess(element)
  46. {
  47. var rect = paper.rect(element.x, element.y, element.width, element.height, 4);
  48. var strokeColor = _cmmnGetColor(element, MAIN_STROKE_COLOR);
  49. rect.attr({"stroke-width": 1,
  50. "stroke": strokeColor,
  51. "fill": "white"
  52. });
  53. }
  54. function _drawVariableServiceTaskIcon(element)
  55. {
  56. _drawTask(element);
  57. if (element.taskType === "mail")
  58. {
  59. _drawSendTaskIcon(paper, element.x + 4, element.y + 4);
  60. }
  61. else if (element.taskType === "camel")
  62. {
  63. _drawCamelTaskIcon(paper, element.x + 4, element.y + 4);
  64. }
  65. else if (element.taskType === "mule")
  66. {
  67. _drawMuleTaskIcon(paper, element.x + 4, element.y + 4);
  68. }
  69. else if (element.taskType === "http")
  70. {
  71. _drawHttpTaskIcon(paper, element.x + 4, element.y + 4);
  72. }
  73. else if (element.stencilIconId)
  74. {
  75. paper.image("../service/stencilitem/" + element.stencilIconId + "/icon", element.x + 4, element.y + 4, 16, 16);
  76. }
  77. else
  78. {
  79. _drawServiceTaskIcon(paper, element.x + 4, element.y + 4);
  80. }
  81. _addHoverLogic(element, "rect", ACTIVITY_STROKE_COLOR);
  82. }
  83. function _drawHttpServiceTask(element)
  84. {
  85. _drawTask(element);
  86. _drawHttpTaskIcon(paper, element.x + 4, element.y + 4);
  87. _addHoverLogic(element, "rect", ACTIVITY_STROKE_COLOR);
  88. }
  89. function _drawHumanTask(element)
  90. {
  91. _drawTask(element);
  92. _drawHumanTaskIcon(paper, element.x + 4, element.y + 4);
  93. _addHoverLogic(element, "rect", ACTIVITY_STROKE_COLOR);
  94. }
  95. function _drawCaseTask(element)
  96. {
  97. _drawTask(element);
  98. _drawCaseTaskIcon(paper, element.x + 1, element.y + 1);
  99. _addHoverLogic(element, "rect", ACTIVITY_STROKE_COLOR);
  100. }
  101. function _drawProcessTask(element)
  102. {
  103. _drawTask(element);
  104. _drawProcessTaskIcon(paper, element.x + 1, element.y + 1);
  105. _addHoverLogic(element, "rect", ACTIVITY_STROKE_COLOR);
  106. }
  107. function _drawScriptTaskIcon(paper, startX, startY)
  108. {
  109. var path1 = paper.path("m 5,2 0,0.094 c 0.23706,0.064 0.53189,0.1645 0.8125,0.375 0.5582,0.4186 1.05109,1.228 1.15625,2.5312 l 8.03125,0 1,0 1,0 c 0,-3 -2,-3 -2,-3 l -10,0 z M 4,3 4,13 2,13 c 0,3 2,3 2,3 l 9,0 c 0,0 2,0 2,-3 L 15,6 6,6 6,5.5 C 6,4.1111 5.5595,3.529 5.1875,3.25 4.8155,2.971 4.5,3 4.5,3 L 4,3 z");
  110. path1.attr({
  111. "opacity": 1,
  112. "stroke": "none",
  113. "fill": "#72a7d0"
  114. });
  115. var scriptTaskIcon = paper.set();
  116. scriptTaskIcon.push(path1);
  117. scriptTaskIcon.transform("T" + startX + "," + startY);
  118. }
  119. function _drawScriptServiceTask(element)
  120. {
  121. _drawTask(element);
  122. _drawScriptTaskIcon(paper, element.x + 4, element.y + 4);
  123. _addHoverLogic(element, "rect", ACTIVITY_STROKE_COLOR);
  124. }
  125. function _drawSendEventServiceTask(element)
  126. {
  127. _drawTask(element);
  128. _drawSendTaskIcon(paper, element.x + 4, element.y + 4);
  129. _addHoverLogic(element, "rect", ACTIVITY_STROKE_COLOR);
  130. }
  131. function _drawDecisionTask(element)
  132. {
  133. _drawTask(element);
  134. _drawDecisionTaskIcon(paper, element.x + 1, element.y + 1);
  135. _addHoverLogic(element, "rect", ACTIVITY_STROKE_COLOR);
  136. }
  137. function _drawServiceTask(element)
  138. {
  139. _drawTask(element);
  140. _drawVariableServiceTaskIcon(element);
  141. _addHoverLogic(element, "rect", ACTIVITY_STROKE_COLOR);
  142. }
  143. function _drawTask(element)
  144. {
  145. var rectAttrs = {};
  146. // Stroke
  147. var strokeColor = _cmmnGetColor(element, ACTIVITY_STROKE_COLOR);
  148. rectAttrs['stroke'] = strokeColor;
  149. var strokeWidth;
  150. if (strokeColor === ACTIVITY_STROKE_COLOR) {
  151. strokeWidth = TASK_STROKE;
  152. } else {
  153. strokeWidth = TASK_HIGHLIGHT_STROKE;
  154. }
  155. var width = element.width - (strokeWidth / 2);
  156. var height = element.height - (strokeWidth / 2);
  157. var rect = paper.rect(element.x, element.y, width, height, 4);
  158. rectAttrs['stroke-width'] = strokeWidth;
  159. // Fill
  160. rectAttrs['fill'] = ACTIVITY_FILL_COLOR;
  161. rect.attr(rectAttrs);
  162. rect.id = element.id;
  163. if (element.name) {
  164. this._drawMultilineText(element.name, element.x, element.y, element.width, element.height, "middle", "middle", 11);
  165. }
  166. }
  167. function _drawTimerEventListener(element)
  168. {
  169. _drawEventListener(element);
  170. _drawTimerEventListenerIcon(paper, element);
  171. _addHoverLogic(element, "rect", ACTIVITY_STROKE_COLOR);
  172. }
  173. function _drawUserEventListener(element)
  174. {
  175. _drawEventListener(element);
  176. _drawUserEventListenerIcon(paper, element);
  177. _addHoverLogic(element, "rect", ACTIVITY_STROKE_COLOR);
  178. }
  179. function _drawVariableEventListener(element)
  180. {
  181. _drawEventListener(element);
  182. _drawVariableEventListenerIcon(paper, element);
  183. _addHoverLogic(element, "rect", ACTIVITY_STROKE_COLOR);
  184. }
  185. function _drawGenericEventListener(element)
  186. {
  187. _drawEventListener(element);
  188. _addHoverLogic(element, "rect", ACTIVITY_STROKE_COLOR);
  189. }
  190. function _drawEventListener(element)
  191. {
  192. var x = element.x + (element.width / 2);
  193. var y = element.y + (element.height / 2);
  194. var circle = paper.circle(x, y, 15);
  195. circle.attr({"stroke-width": 1,
  196. "stroke": "black",
  197. "fill": "white"
  198. });
  199. circle.id = element.id;
  200. }
  201. function _drawMilestone(element)
  202. {
  203. var rectAttrs = {};
  204. // Stroke
  205. var strokeColor = _cmmnGetColor(element, ACTIVITY_STROKE_COLOR);
  206. rectAttrs['stroke'] = strokeColor;
  207. var strokeWidth;
  208. if (strokeColor === ACTIVITY_STROKE_COLOR) {
  209. strokeWidth = TASK_STROKE;
  210. } else {
  211. strokeWidth = TASK_HIGHLIGHT_STROKE;
  212. }
  213. var width = element.width - (strokeWidth / 2);
  214. var height = element.height - (strokeWidth / 2);
  215. var rect = paper.rect(element.x, element.y, width, height, 24);
  216. rectAttrs['stroke-width'] = strokeWidth;
  217. // Fill
  218. rectAttrs['fill'] = WHITE_FILL_COLOR;
  219. rect.attr(rectAttrs);
  220. rect.id = element.id;
  221. if (element.name) {
  222. this._drawMultilineText(element.name, element.x, element.y, element.width, element.height, "middle", "middle", 11);
  223. }
  224. }
  225. function _drawStage(element)
  226. {
  227. var rectAttrs = {};
  228. // Stroke
  229. var strokeColor = _cmmnGetColor(element, ACTIVITY_STROKE_COLOR);
  230. rectAttrs['stroke'] = strokeColor;
  231. var strokeWidth;
  232. if (strokeColor === ACTIVITY_STROKE_COLOR) {
  233. strokeWidth = TASK_STROKE;
  234. } else {
  235. strokeWidth = TASK_HIGHLIGHT_STROKE;
  236. }
  237. var width = element.width - (strokeWidth / 2);
  238. var height = element.height - (strokeWidth / 2);
  239. var rect = paper.rect(element.x, element.y, width, height, 16);
  240. rectAttrs['stroke-width'] = strokeWidth;
  241. // Fill
  242. rectAttrs['fill'] = WHITE_FILL_COLOR;
  243. rect.attr(rectAttrs);
  244. rect.id = element.id;
  245. if (element.name) {
  246. this._drawMultilineText(element.name, element.x + 10, element.y + 5, element.width, element.height, "start", "top", 11);
  247. }
  248. }
  249. function _drawPlanModel(element)
  250. {
  251. var rectAttrs = {};
  252. // Stroke
  253. var strokeColor = _cmmnGetColor(element, ACTIVITY_STROKE_COLOR);
  254. rectAttrs['stroke'] = strokeColor;
  255. var strokeWidth;
  256. if (strokeColor === ACTIVITY_STROKE_COLOR) {
  257. strokeWidth = TASK_STROKE;
  258. } else {
  259. strokeWidth = TASK_HIGHLIGHT_STROKE;
  260. }
  261. var width = element.width - (strokeWidth / 2);
  262. var height = element.height - (strokeWidth / 2);
  263. var rect = paper.rect(element.x, element.y, width, height, 4);
  264. rectAttrs['stroke-width'] = strokeWidth;
  265. // Fill
  266. rectAttrs['fill'] = WHITE_FILL_COLOR;
  267. rect.attr(rectAttrs);
  268. rect.id = element.id;
  269. var path1 = paper.path("M20 55 L37 34 L275 34 L291 55");
  270. path1.attr({
  271. "opacity": 1,
  272. "stroke": strokeColor,
  273. "fill": "#ffffff"
  274. });
  275. var planModelHeader = paper.set();
  276. planModelHeader.push(path1);
  277. planModelHeader.translate(element.x, element.y - 55);
  278. if (element.name) {
  279. this._drawMultilineText(element.name, element.x + 10, element.y - 16, 275, element.height, "middle", "top", 11);
  280. }
  281. }
  282. function _drawEntryCriterion(element)
  283. {
  284. var strokeColor = _cmmnGetColor(element, MAIN_STROKE_COLOR);
  285. var rhombus = paper.path("M" + element.x + " " + (element.y + (element.height / 2)) +
  286. "L" + (element.x + (element.width / 2)) + " " + (element.y + element.height) +
  287. "L" + (element.x + element.width) + " " + (element.y + (element.height / 2)) +
  288. "L" + (element.x + (element.width / 2)) + " " + element.y + "z"
  289. );
  290. // Fill
  291. var gatewayFillColor = WHITE_FILL_COLOR;
  292. // Opacity
  293. var gatewayOpacity = 1.0;
  294. rhombus.attr("stroke-width", 1);
  295. rhombus.attr("stroke", strokeColor);
  296. rhombus.attr("fill", gatewayFillColor);
  297. rhombus.attr("fill-opacity", gatewayOpacity);
  298. rhombus.id = element.id;
  299. }
  300. function _drawExitCriterion(element)
  301. {
  302. var strokeColor = _cmmnGetColor(element, MAIN_STROKE_COLOR);
  303. var rhombus = paper.path("M" + element.x + " " + (element.y + (element.height / 2)) +
  304. "L" + (element.x + (element.width / 2)) + " " + (element.y + element.height) +
  305. "L" + (element.x + element.width) + " " + (element.y + (element.height / 2)) +
  306. "L" + (element.x + (element.width / 2)) + " " + element.y + "z"
  307. );
  308. // Fill
  309. var gatewayFillColor = '#000000';
  310. // Opacity
  311. var gatewayOpacity = 1.0;
  312. rhombus.attr("stroke-width", 1);
  313. rhombus.attr("stroke", strokeColor);
  314. rhombus.attr("fill", gatewayFillColor);
  315. rhombus.attr("fill-opacity", gatewayOpacity);
  316. rhombus.id = element.id;
  317. }
  318. function _drawMultilineText(text, x, y, boxWidth, boxHeight, horizontalAnchor, verticalAnchor, fontSize)
  319. {
  320. if (!text || text == "")
  321. {
  322. return;
  323. }
  324. var textBoxX, textBoxY;
  325. var width = boxWidth - (2 * TEXT_PADDING);
  326. if (horizontalAnchor === "middle")
  327. {
  328. textBoxX = x + (boxWidth / 2);
  329. }
  330. else if (horizontalAnchor === "start")
  331. {
  332. textBoxX = x;
  333. }
  334. textBoxY = y + (boxHeight / 2);
  335. var t = paper.text(textBoxX + TEXT_PADDING, textBoxY + TEXT_PADDING).attr({
  336. "text-anchor" : horizontalAnchor,
  337. "font-family" : "Arial",
  338. "font-size" : fontSize,
  339. "fill" : "#373e48"
  340. });
  341. var abc = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  342. t.attr({
  343. "text" : abc
  344. });
  345. var letterWidth = t.getBBox().width / abc.length;
  346. t.attr({
  347. "text" : text
  348. });
  349. var removedLineBreaks = text.split("\n");
  350. var x = 0, s = [];
  351. for (var r = 0; r < removedLineBreaks.length; r++)
  352. {
  353. var words = removedLineBreaks[r].split(" ");
  354. for ( var i = 0; i < words.length; i++) {
  355. var l = words[i].length;
  356. if (x + (l * letterWidth) > width) {
  357. s.push("\n");
  358. x = 0;
  359. }
  360. x += l * letterWidth;
  361. s.push(words[i] + " ");
  362. }
  363. s.push("\n");
  364. x = 0;
  365. }
  366. t.attr({
  367. "text" : s.join("")
  368. });
  369. if (verticalAnchor && verticalAnchor === "top")
  370. {
  371. t.attr({"y": y + (t.getBBox().height / 2)});
  372. }
  373. }
  374. function _drawAssociation(flow){
  375. var polyline = new Polyline(flow.id, flow.waypoints, ASSOCIATION_STROKE, paper);
  376. polyline.element = paper.path(polyline.path);
  377. polyline.element.attr({"stroke-width": ASSOCIATION_STROKE});
  378. polyline.element.attr({"stroke-dasharray": ". "});
  379. polyline.element.attr({"stroke":"#585858"});
  380. polyline.element.id = flow.id;
  381. var polylineInvisible = new Polyline(flow.id, flow.waypoints, ASSOCIATION_STROKE, paper);
  382. polylineInvisible.element = paper.path(polyline.path);
  383. polylineInvisible.element.attr({
  384. "opacity": 0,
  385. "stroke-width": 8,
  386. "stroke" : "#000000"
  387. });
  388. _showTip(jQuery(polylineInvisible.element.node), flow);
  389. polylineInvisible.element.mouseover(function() {
  390. paper.getById(polyline.element.id).attr({"stroke":"blue"});
  391. });
  392. polylineInvisible.element.mouseout(function() {
  393. paper.getById(polyline.element.id).attr({"stroke":"#585858"});
  394. });
  395. }
  396. function _drawArrowHead(line, connectionType)
  397. {
  398. var doubleArrowWidth = 2 * ARROW_WIDTH;
  399. var arrowHead = paper.path("M0 0L-" + (ARROW_WIDTH / 2 + .5) + " -" + doubleArrowWidth + "L" + (ARROW_WIDTH/2 + .5) + " -" + doubleArrowWidth + "z");
  400. // anti smoothing
  401. if (this.strokeWidth%2 == 1)
  402. line.x2 += .5, line.y2 += .5;
  403. arrowHead.transform("t" + line.x2 + "," + line.y2 + "");
  404. arrowHead.transform("...r" + Raphael.deg(line.angle - Math.PI / 2) + " " + 0 + " " + 0);
  405. arrowHead.attr("fill", "#585858");
  406. arrowHead.attr("stroke-width", SEQUENCEFLOW_STROKE);
  407. arrowHead.attr("stroke", "#585858");
  408. return arrowHead;
  409. }