CanDb.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. Copyright (c) 2015, 2016 Hubert Denkmair <hubert@denkmair.de>
  3. This file is part of cangaroo.
  4. cangaroo is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 2 of the License, or
  7. (at your option) any later version.
  8. cangaroo is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with cangaroo. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #include "CanDb.h"
  16. #include <QFileInfo>
  17. #include <QDomDocument>
  18. #include <core/Backend.h>
  19. CanDb::CanDb()
  20. {
  21. }
  22. QString CanDb::getFileName()
  23. {
  24. QFileInfo fi(getPath());
  25. return fi.fileName();
  26. }
  27. QString CanDb::getDirectory()
  28. {
  29. QFileInfo fi(getPath());
  30. return fi.absolutePath();
  31. }
  32. CanDbNode *CanDb::getOrCreateNode(QString node_name)
  33. {
  34. if (!_nodes.contains(node_name)) {
  35. CanDbNode *node = new CanDbNode(this);
  36. node->setName(node_name);
  37. _nodes[node_name] = node;
  38. return node;
  39. } else {
  40. return _nodes[node_name];
  41. }
  42. }
  43. CanDbMessage *CanDb::getMessageById(uint32_t raw_id)
  44. {
  45. if (_messages.contains(raw_id)) {
  46. return _messages[raw_id];
  47. } else {
  48. return 0;
  49. }
  50. }
  51. void CanDb::addMessage(CanDbMessage *msg)
  52. {
  53. _messages[msg->getRaw_id()] = msg;
  54. }
  55. QString CanDb::getComment() const
  56. {
  57. return _comment;
  58. }
  59. void CanDb::setComment(const QString &comment)
  60. {
  61. _comment = comment;
  62. }
  63. bool CanDb::saveXML(Backend &backend, QDomDocument &xml, QDomElement &root)
  64. {
  65. (void) backend;
  66. (void) xml;
  67. root.setAttribute("type", "dbc");
  68. root.setAttribute("filename", _path);
  69. return true;
  70. }