PageRenderTime 47ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/src/data/ArtifactData.cpp

http://github.com/gregsmirnov/bouml
C++ | 477 lines | 363 code | 82 blank | 32 comment | 93 complexity | 0fae1befb025ffed22d1fb0178f34fa0 MD5 | raw file
Possible License(s): GPL-2.0
  1. // *************************************************************************
  2. //
  3. // Copyright 2004-2010 Bruno PAGES .
  4. //
  5. // This file is part of the BOUML Uml Toolkit.
  6. //
  7. // This program is free software; you can redistribute it and/or modify
  8. // it under the terms of the GNU General Public License as published by
  9. // the Free Software Foundation; either version 2 of the License, or
  10. // (at your option) any later version.
  11. //
  12. // This program is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. // GNU General Public License for more details.
  16. //
  17. // You should have received a copy of the GNU General Public License
  18. // along with this program; if not, write to the Free Software
  19. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20. //
  21. // e-mail : bouml@free.fr
  22. // home : http://bouml.free.fr
  23. //
  24. // *************************************************************************
  25. #include <qcursor.h>
  26. #include "ArtifactData.h"
  27. #include "BrowserClass.h"
  28. #include "ClassData.h"
  29. #include "BrowserArtifact.h"
  30. #include "BrowserDeploymentDiagram.h"
  31. #include "ArtifactDialog.h"
  32. #include "GenerationSettings.h"
  33. #include "myio.h"
  34. #include "ToolCom.h"
  35. #include "mu.h"
  36. ArtifactData::ArtifactData() : associated(0) {
  37. }
  38. // doesn't copy associated classes or artifacts
  39. ArtifactData::ArtifactData(ArtifactData * model, BrowserNode * bn)
  40. : SimpleData(model), associated(0) {
  41. browser_node = bn;
  42. cpp_h = model->cpp_h;
  43. cpp_src = model->cpp_src;
  44. java_src = model->java_src;
  45. php_src = model->php_src;
  46. python_src = model->python_src;
  47. idl_src = model->idl_src;
  48. #if 0
  49. if (model->associated != 0) {
  50. associated = new QPtrDict<BrowserArtifact>();
  51. QPtrDictIterator<BrowserArtifact> it(*(model->associated));
  52. while (it.current()) {
  53. associated->insert(it.current(), it.current());
  54. connect(it.current()->get_data(), SIGNAL(deleted()),
  55. this, SLOT(on_delete()));
  56. ++it;
  57. }
  58. }
  59. #endif
  60. }
  61. ArtifactData::~ArtifactData() {
  62. if (associated != 0)
  63. delete associated;
  64. }
  65. void ArtifactData::edit() {
  66. setName(browser_node->get_name());
  67. (new ArtifactDialog(this))->show();
  68. }
  69. void ArtifactData::use_default_cpp_h() {
  70. cpp_h = GenerationSettings::cpp_default_header_content();
  71. }
  72. void ArtifactData::use_default_cpp_src() {
  73. cpp_src = GenerationSettings::cpp_default_source_content();
  74. }
  75. void ArtifactData::use_default_java_src() {
  76. java_src = GenerationSettings::java_default_source_content();
  77. }
  78. void ArtifactData::use_default_php_src() {
  79. php_src = GenerationSettings::php_default_source_content();
  80. }
  81. void ArtifactData::use_default_python_src() {
  82. python_src = GenerationSettings::python_default_source_content();
  83. }
  84. void ArtifactData::use_default_idl_src() {
  85. idl_src = GenerationSettings::idl_default_source_content();
  86. }
  87. //
  88. void ArtifactData::send_uml_def(ToolCom * com, BrowserNode * bn,
  89. const QString & comment) {
  90. BasicData::send_uml_def(com, bn, comment);
  91. const QValueList<BrowserClass *> & l =
  92. ((BrowserArtifact *) browser_node)->get_associated_classes();
  93. QValueList<BrowserClass *>::ConstIterator itl;
  94. QValueList<BrowserClass *>::ConstIterator end = l.end();
  95. unsigned n;
  96. n = 0;
  97. for (itl = l.begin(); itl != end; ++itl)
  98. if (! (*itl)->deletedp())
  99. n += 1;
  100. com->write_unsigned(n);
  101. for (itl = l.begin(); itl != end; ++itl)
  102. if (! (*itl)->deletedp())
  103. (*itl)->write_id(com);
  104. //
  105. if (associated == 0)
  106. com->write_unsigned(0);
  107. else {
  108. QPtrDictIterator<BrowserArtifact> itd(*associated);
  109. n = 0;
  110. while (itd.current()) {
  111. if (! itd.current()->deletedp())
  112. n += 1;
  113. ++itd;
  114. }
  115. com->write_unsigned(n);
  116. itd.toFirst();
  117. while (itd.current()) {
  118. if (! itd.current()->deletedp())
  119. itd.current()->write_id(com);
  120. ++itd;
  121. }
  122. }
  123. }
  124. void ArtifactData::send_cpp_def(ToolCom * com) {
  125. com->write_string(cpp_h);
  126. com->write_string(cpp_src);
  127. }
  128. void ArtifactData::send_java_def(ToolCom * com) {
  129. com->write_string(java_src);
  130. }
  131. void ArtifactData::send_php_def(ToolCom * com) {
  132. com->write_string(php_src);
  133. }
  134. void ArtifactData::send_python_def(ToolCom * com) {
  135. com->write_string(python_src);
  136. }
  137. void ArtifactData::send_idl_def(ToolCom * com) {
  138. com->write_string(idl_src);
  139. }
  140. bool ArtifactData::tool_cmd(ToolCom * com, const char * args,
  141. BrowserNode * bn,
  142. const QString & comment) {
  143. if (((unsigned char) args[-1]) >= firstSetCmd) {
  144. if (!bn->is_writable() && !root_permission())
  145. com->write_ack(FALSE);
  146. else {
  147. switch ((unsigned char) args[-1]) {
  148. case setCppHCmd:
  149. cpp_h = args;
  150. break;
  151. case setCppSrcCmd:
  152. cpp_src = args;
  153. break;
  154. case setJavaSrcCmd:
  155. java_src = args;
  156. break;
  157. case setPhpSrcCmd:
  158. php_src = args;
  159. break;
  160. case setPythonSrcCmd:
  161. python_src = args;
  162. break;
  163. case setIdlSrcCmd:
  164. idl_src = args;
  165. break;
  166. case addAssocArtifactCmd:
  167. {
  168. BrowserArtifact * cp = (BrowserArtifact *) com->get_id(args);
  169. associate(cp);
  170. }
  171. break;
  172. case removeAssocArtifactCmd:
  173. {
  174. BrowserArtifact * cp = (BrowserArtifact *) com->get_id(args);
  175. unassociate(cp);
  176. }
  177. break;
  178. case removeAllAssocArtifactsCmd:
  179. if (associated != 0) {
  180. QPtrDictIterator<BrowserArtifact> it(*associated);
  181. while (it.current()) {
  182. disconnect(it.current()->get_data(), SIGNAL(deleted()),
  183. this, SLOT(on_delete()));
  184. ++it;
  185. }
  186. delete associated;
  187. associated = 0;
  188. }
  189. break;
  190. default:
  191. return BasicData::tool_cmd(com, args, bn, comment);
  192. }
  193. // ok case
  194. bn->modified();
  195. bn->package_modified();
  196. modified();
  197. com->write_ack(TRUE);
  198. }
  199. }
  200. else
  201. return BasicData::tool_cmd(com, args, bn, comment);
  202. return TRUE;
  203. }
  204. void ArtifactData::on_delete() {
  205. if (associated != 0) {
  206. bool modp = FALSE;
  207. QPtrDictIterator<BrowserArtifact> it(*associated);
  208. while (it.current()) {
  209. if (it.current()->deletedp()) {
  210. modp = TRUE;
  211. associated->remove(it.current()); // update it
  212. }
  213. else
  214. ++it;
  215. }
  216. if (modp)
  217. modified();
  218. }
  219. browser_node->on_delete();
  220. }
  221. bool ArtifactData::decldefbody_contain(const QString & s, bool cs,
  222. BrowserNode *) {
  223. return ((QString(get_cpp_h()).find(s, 0, cs) != -1) ||
  224. (QString(get_cpp_src()).find(s, 0, cs) != -1) ||
  225. (QString(get_java_src()).find(s, 0, cs) != -1) ||
  226. (QString(get_php_src()).find(s, 0, cs) != -1) ||
  227. (QString(get_python_src()).find(s, 0, cs) != -1) ||
  228. (QString(get_idl_src()).find(s, 0, cs) != -1));
  229. }
  230. void ArtifactData::associate(BrowserArtifact * other) {
  231. if ((associated == 0) || (associated->find(other) == 0)) {
  232. connect(other->get_data(), SIGNAL(deleted()), this, SLOT(on_delete()));
  233. if (associated == 0)
  234. associated = new QPtrDict<BrowserArtifact>;
  235. associated->insert(other, other);
  236. browser_node->modified();
  237. browser_node->package_modified();
  238. modified();
  239. }
  240. }
  241. void ArtifactData::unassociate(BrowserArtifact * other) {
  242. disconnect(other->get_data(), SIGNAL(deleted()), this, SLOT(on_delete()));
  243. associated->remove(other);
  244. browser_node->modified();
  245. browser_node->package_modified();
  246. modified();
  247. }
  248. void ArtifactData::update_associated(QPtrDict<BrowserArtifact> & d) {
  249. if (associated != 0) {
  250. QPtrDictIterator<BrowserArtifact> it(*associated);
  251. while (it.current()) {
  252. if (d.find(it.current()) == 0) {
  253. disconnect(it.current()->get_data(), SIGNAL(deleted()),
  254. this, SLOT(on_delete()));
  255. associated->remove(it.current());
  256. }
  257. else
  258. ++it;
  259. }
  260. }
  261. else
  262. associated = new QPtrDict<BrowserArtifact>((d.count() >> 4) + 1);
  263. QPtrDictIterator<BrowserArtifact> it(d);
  264. while (it.current()) {
  265. if (associated->find(it.current()) == 0) {
  266. associated->insert(it.current(), it.current());
  267. if (associated->size() < (associated->count() >> 4))
  268. associated->resize((associated->count() >> 4) + 1);
  269. connect(it.current()->get_data(), SIGNAL(deleted()),
  270. this, SLOT(on_delete()));
  271. }
  272. ++it;
  273. }
  274. }
  275. //
  276. // translate plug out release < 2.0
  277. void ArtifactData::convert_add_include_artifact() {
  278. if (!cpp_src.isEmpty()) {
  279. int index = cpp_src.find("#include \"UmlComponent.h\"");
  280. if (index != -1) {
  281. QCString s = cpp_src.SharedStr::operator QCString();
  282. s.insert(index, "#include \"UmlArtifact.h\"\n");
  283. cpp_src = s;
  284. }
  285. }
  286. }
  287. //
  288. void ArtifactData::save(QTextStream & st, QString & warning) const {
  289. BasicData::save(st, warning);
  290. bool a_text = (stereotype == "text");
  291. if (a_text || (stereotype == "source")) {
  292. if (!a_text && !cpp_h.isEmpty()) {
  293. nl_indent(st);
  294. st << "cpp_h ";
  295. save_string(cpp_h, st);
  296. }
  297. if (!cpp_src.isEmpty()) {
  298. nl_indent(st);
  299. st << "cpp_src ";
  300. save_string(cpp_src, st);
  301. }
  302. if (!java_src.isEmpty()) {
  303. nl_indent(st);
  304. st << "java_src ";
  305. save_string(java_src, st);
  306. }
  307. if (!php_src.isEmpty()) {
  308. nl_indent(st);
  309. st << "php_src ";
  310. save_string(php_src, st);
  311. }
  312. if (!python_src.isEmpty()) {
  313. nl_indent(st);
  314. st << "python_src ";
  315. save_string(python_src, st);
  316. }
  317. if (!idl_src.isEmpty()) {
  318. nl_indent(st);
  319. st << "idl_src ";
  320. save_string(idl_src, st);
  321. }
  322. }
  323. else if (associated != 0) {
  324. nl_indent(st);
  325. st << "associated_artifacts";
  326. indent(+1);
  327. QPtrDictIterator<BrowserArtifact> it(*associated);
  328. while (it.current()) {
  329. nl_indent(st);
  330. it.current()->save(st, TRUE, warning);
  331. ++it;
  332. }
  333. indent(-1);
  334. nl_indent(st);
  335. st << "end";
  336. }
  337. }
  338. void ArtifactData::read(char * & st, char * & k) {
  339. BasicData::read(st, k); // updates k
  340. cpp_h = QString::null;
  341. cpp_src = QString::null;
  342. java_src = QString::null;
  343. php_src = QString::null;
  344. python_src = QString::null;
  345. idl_src = QString::null;
  346. if ((stereotype == "text") && (read_file_format() < 42))
  347. stereotype = "_text";
  348. if ((stereotype == "source") || (stereotype == "text")) {
  349. if (!strcmp(k, "cpp_h")) {
  350. cpp_h = read_string(st);
  351. k = read_keyword(st);
  352. }
  353. if (!strcmp(k, "cpp_src")) {
  354. // old -> new version
  355. QCString s = read_string(st);
  356. int index;
  357. if ((index = s.find("${class_attributes}\n${operations}")) != -1)
  358. s.replace(index, 33, "${members}");
  359. else if ((index = s.find("${class_attributes}\r\n${operations}")) != -1)
  360. s.replace(index, 34, "${members}");
  361. cpp_src = s;
  362. k = read_keyword(st);
  363. }
  364. if (!strcmp(k, "java_src")) {
  365. java_src = read_string(st);
  366. k = read_keyword(st);
  367. }
  368. if (!strcmp(k, "php_src")) {
  369. php_src = read_string(st);
  370. k = read_keyword(st);
  371. }
  372. if (!strcmp(k, "python_src")) {
  373. python_src = read_string(st);
  374. k = read_keyword(st);
  375. }
  376. if (!strcmp(k, "idl_src")) {
  377. idl_src = read_string(st);
  378. k = read_keyword(st);
  379. }
  380. }
  381. else if (!strcmp(k, "associated_artifacts") ||
  382. ((read_file_format() < 20) && !strcmp(k, "associated_components"))) {
  383. associated = new QPtrDict<BrowserArtifact>();
  384. while (strcmp(k = read_keyword(st), "end")) {
  385. BrowserArtifact * c =
  386. BrowserArtifact::read_ref(st, k); // k not updated
  387. associated->insert(c, c);
  388. connect(c->get_data(), SIGNAL(deleted()),
  389. this, SLOT(on_delete()));
  390. }
  391. if (associated->size() < (associated->count() >> 4))
  392. associated->resize((associated->count() >> 4) + 1);
  393. k = read_keyword(st);
  394. }
  395. }