ccUtils.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //##########################################################################
  2. //# #
  3. //# CLOUDCOMPARE #
  4. //# #
  5. //# This program is free software; you can redistribute it and/or modify #
  6. //# it under the terms of the GNU General Public License as published by #
  7. //# the Free Software Foundation; version 2 or later of the License. #
  8. //# #
  9. //# This program is distributed in the hope that it will be useful, #
  10. //# but WITHOUT ANY WARRANTY; without even the implied warranty of #
  11. //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
  12. //# GNU General Public License for more details. #
  13. //# #
  14. //# COPYRIGHT: CloudCompare project #
  15. //# #
  16. //##########################################################################
  17. #include "ccConsole.h"
  18. #include "ccUtils.h"
  19. //Qt
  20. #include <QClipboard>
  21. #include <QApplication>
  22. namespace ccUtils
  23. {
  24. void DisplayLockedVerticesWarning(const QString& meshName, bool displayAsError)
  25. {
  26. QString message = QString("Vertices of mesh '%1' are locked (they may be shared by multiple entities for instance).\nYou should call this method directly on the vertices cloud.\n(warning: all entities depending on this cloud will be impacted!)").arg(meshName);
  27. if (displayAsError)
  28. ccConsole::Error(message);
  29. else
  30. ccConsole::Warning(message);
  31. }
  32. bool GetVectorFromClipboard(CCVector3d& vector, bool sendErrors/*=true*/)
  33. {
  34. const QClipboard* clipboard = QApplication::clipboard();
  35. if (!clipboard)
  36. {
  37. if (sendErrors)
  38. {
  39. ccLog::Error("Clipboard not available");
  40. }
  41. return false;
  42. }
  43. QString text = clipboard->text().trimmed();
  44. if (text.startsWith('[') || text.startsWith('{') || text.startsWith('('))
  45. {
  46. text = text.right(text.length() - 1);
  47. }
  48. if (text.endsWith(']') || text.endsWith('}') || text.endsWith(')'))
  49. {
  50. text = text.left(text.length() - 1);
  51. }
  52. if (text.isEmpty())
  53. {
  54. return false;
  55. }
  56. QStringList tokens = text.split(QRegExp("\\s+"), QString::SkipEmptyParts);
  57. if (tokens.size() != 3)
  58. {
  59. tokens = text.split(';', QString::SkipEmptyParts);
  60. if (tokens.size() != 3)
  61. {
  62. tokens = text.split(',', QString::SkipEmptyParts);
  63. if (tokens.size() != 3)
  64. {
  65. if (text.length() > 64)
  66. {
  67. text.truncate(61);
  68. text += "...";
  69. }
  70. if (sendErrors)
  71. {
  72. ccLog::Error("Unrecognized format: " + text);
  73. }
  74. return false;
  75. }
  76. }
  77. }
  78. for (unsigned char i = 0; i < 3; ++i)
  79. {
  80. bool ok = false;
  81. vector.u[i] = tokens[i].toDouble(&ok);
  82. if (!ok)
  83. {
  84. if (sendErrors)
  85. {
  86. ccLog::Error("Invalid value: " + tokens[i]);
  87. }
  88. return false;
  89. }
  90. }
  91. return true;
  92. }
  93. }