• R/O
  • SSH
  • HTTPS

qrobosdk: コミット


コミットメタ情報

リビジョン1805 (tree)
日時2010-04-26 10:24:30
作者satofumi

ログメッセージ

fixed UrgDrawWidget bug

変更サマリ

差分

--- trunk/widgets/UrgDrawWidget/UrgDrawWidget.cpp (revision 1804)
+++ trunk/widgets/UrgDrawWidget/UrgDrawWidget.cpp (revision 1805)
@@ -66,6 +66,7 @@
6666 DrawMode draw_mode_;
6767 long draw_period_;
6868 long last_redraw_;
69+ long last_timestamp_;
6970
7071 typedef deque<DrawData> DataArray;
7172 DataArray draw_data_;
@@ -83,9 +84,9 @@
8384 pImpl(UrgDrawWidget* widget)
8485 : widget_(widget),
8586 pixel_per_mm_(DefaultPixelPerMm), draw_mode_(Lines), draw_period_(0),
86- last_redraw_(0), width_(MinimumWidth), height_(MinimumHeight),
87- clear_color_(Qt::white), rotate_offset_(Position<long>(0, 0, deg(90))),
88- now_pressed_(false),
87+ last_redraw_(0), last_timestamp_(0), width_(MinimumWidth),
88+ height_(MinimumHeight), clear_color_(Qt::white),
89+ rotate_offset_(Position<long>(0, 0, deg(90))), now_pressed_(false),
8990 line_color_(0.2f, 0.2f, 1.0f, 0.6f)
9091 {
9192 }
@@ -102,11 +103,21 @@
102103
103104 void removeOldData(long timestamp)
104105 {
106+ if (draw_data_.empty()) {
107+ return;
108+ }
109+
110+ // タイムスタンプが異常な場合、全てのデータをクリアする
111+ if (draw_data_.back().timestamp > timestamp) {
112+ draw_data_.clear();
113+ return;
114+ }
115+
105116 int index = 0;
106117 for (DataArray::iterator it = draw_data_.begin();
107118 it != draw_data_.end(); ++it, ++index) {
108- long difference = it->timestamp - timestamp;
109- if (difference >= draw_period_) {
119+ long difference = timestamp - it->timestamp;
120+ if (difference < draw_period_) {
110121 break;
111122 }
112123 }
@@ -278,7 +289,9 @@
278289 line_it != draw_data_.end(); ++line_it) {
279290
280291 Color& line_color = line_it->line_color;
281- glColor4d(line_color.r, line_color.g, line_color.b, line_color.a);
292+ double diff = last_timestamp_ - line_it->timestamp;
293+ double alpha = 1.0 - diff / draw_period_;
294+ glColor4d(line_color.r, line_color.g, line_color.b, alpha);
282295
283296 vector<Point<long> >& line_data = line_it->point_data;;
284297 vector<Point<long> >::iterator end_it = line_data.end();
@@ -299,7 +312,6 @@
299312 }
300313
301314 // 測定点の描画
302- glColor3d(1.0, 0.0, 0.0);
303315 double base_size = 1.4;
304316 double mm_pixel = max(base_size / pixel_per_mm_, base_size);
305317 glPointSize(mm_pixel);
@@ -308,6 +320,11 @@
308320 for (DataArray::iterator line_it = draw_data_.begin();
309321 line_it != draw_data_.end(); ++line_it) {
310322
323+ // !!! 関数にする
324+ double diff = last_timestamp_ - line_it->timestamp;
325+ double alpha = 1.0 - diff / draw_period_;
326+ glColor4d(1.0, 0.0, 0.0, alpha);
327+
311328 vector<Point<long> >::iterator end_it = line_it->point_data.end();
312329 for (vector<Point<long> >::iterator it = line_it->point_data.begin();
313330 it != end_it; ++it) {
@@ -364,6 +381,7 @@
364381 draw_data_.push_back(DrawData(*intensity_point_data, timestamp,
365382 Color(1.0f, 0.0f, 1.0f, 0.7f)));
366383 }
384+ last_timestamp_ = timestamp;
367385
368386 return true;
369387 }
--- trunk/libs/lua/luabindInput.cpp (revision 1804)
+++ trunk/libs/lua/luabindInput.cpp (revision 1805)
@@ -26,7 +26,7 @@
2626 .def(constructor<const char*>())
2727 .def("size", &Utf8::size)
2828 .def("ch", &Utf8::ch)
29- .def("c_str", &Utf8::c_str)
29+ .def("toStdString", &Utf8::toStdString)
3030 .def("substr", &Utf8::substr)
3131 .def("pop_back", &Utf8::pop_back),
3232
--- trunk/libs/gui/Font.cpp (revision 1804)
+++ trunk/libs/gui/Font.cpp (revision 1805)
@@ -128,7 +128,6 @@
128128 Font::Font(const char* font_file, size_t size, bool transparent)
129129 : pimpl(new pImpl(font_file, size, transparent))
130130 {
131- fprintf(stderr, "Font::Font(const char* font_file, size_t size, bool transparent)\n");
132131 // DefaultSize のフォントを生成し、フォントリソースが有効かを確認する
133132 pimpl->is_valid_ = (resource()) ? true : false;
134133 if (! pimpl->is_valid_) {
@@ -142,7 +141,6 @@
142141 rhs.pimpl->font_size_,
143142 rhs.pimpl->transparent_))
144143 {
145- fprintf(stderr, "Font::Font(const Font& rhs)\n");
146144 // pimpl 自体がコピーされないようにするため
147145 pimpl->foreground_ = rhs.pimpl->foreground_;
148146 pimpl->background_ = rhs.pimpl->background_;
@@ -151,7 +149,6 @@
151149
152150 Font& Font::operator = (const Font& rhs)
153151 {
154- fprintf(stderr, "Font& Font::operator = (const Font& rhs)\n");
155152 // pimpl 自体がコピーされないようにするため
156153 this->pimpl->font_file_ = rhs.pimpl->font_file_;
157154 this->pimpl->font_size_ = rhs.pimpl->font_size_;
@@ -165,7 +162,6 @@
165162
166163 Font::~Font(void)
167164 {
168- fprintf(stderr, "~Font()\n");
169165 }
170166
171167
--- trunk/libs/gui/Layer.cpp (revision 1804)
+++ trunk/libs/gui/Layer.cpp (revision 1805)
@@ -78,13 +78,21 @@
7878
7979 void Layer::push_front(Component* component)
8080 {
81- pimpl->components_.push_back(component);
81+ const Components::iterator it =
82+ find(pimpl->components_.begin(), pimpl->components_.end(), component);
83+ if (it == pimpl->components_.end()) {
84+ pimpl->components_.push_back(component);
85+ }
8286 }
8387
8488
8589 void Layer::push_back(Component* component)
8690 {
87- pimpl->components_.push_front(component);
91+ const Components::iterator it =
92+ find(pimpl->components_.begin(), pimpl->components_.end(), component);
93+ if (it == pimpl->components_.end()) {
94+ pimpl->components_.push_front(component);
95+ }
8896 }
8997
9098
--- trunk/libs/gui/TextFadeSurface.cpp (revision 1804)
+++ trunk/libs/gui/TextFadeSurface.cpp (revision 1805)
@@ -35,7 +35,7 @@
3535 Utf8 utf8_text(text);
3636 size_t n = utf8_text.size();
3737 for (size_t i = 0; i < n; ++i) {
38- string ch = utf8_text.substr(i, 1).c_str();
38+ string ch = utf8_text.substr(i, 1).toStdString();
3939 Surface* surface = new TextSurface(font, ch.c_str());
4040 text_surfaces_.push_back(surface);
4141 rect_.w += surface->rect().w;
@@ -101,7 +101,6 @@
101101
102102 TextFadeSurface::~TextFadeSurface(void)
103103 {
104- fprintf(stderr, "~TextFadeSurface()\n");
105104 }
106105
107106
--- trunk/libs/gui/TextSurface.cpp (revision 1804)
+++ trunk/libs/gui/TextSurface.cpp (revision 1805)
@@ -82,7 +82,6 @@
8282
8383 TextSurface::~TextSurface(void)
8484 {
85- fprintf(stderr, "~TextSurface()\n");
8685 }
8786
8887
--- trunk/libs/input/convertToJp.cpp (revision 1804)
+++ trunk/libs/input/convertToJp.cpp (revision 1805)
@@ -32,7 +32,7 @@
3232 }
3333
3434
35-std::string qrk::convertToJp(const char* raw_text, bool is_roman)
35+std::string qrk::convertToJp(const std::string& raw_text, bool is_roman)
3636 {
3737 const unsigned short* table =
3838 (is_roman) ? &RomanTable[0][0][0] : &KanaTable[0][0][0];
--- trunk/libs/input/convertToRoman.cpp (revision 1804)
+++ trunk/libs/input/convertToRoman.cpp (revision 1805)
@@ -48,13 +48,13 @@
4848
4949
5050 void convertUsingInput(Utf8& created_jp_utf8, string& created_roman,
51- const Utf8& jp_text, const char *current_input)
51+ const Utf8& jp_text, const string& current_input)
5252 {
5353 // 順に変換候補を使ったローマ字の文字列の生成を行い、
5454 // 変換に失敗した時点で戻る
5555 string created_jp;
5656 size_t used_jp_index = 0;
57- const char* input = current_input;
57+ const char* input = current_input.c_str();
5858 while (*input != '\0') {
5959 bool matched = false;
6060 const unsigned short* pattern = &RomanTable[0][0][0];
@@ -156,7 +156,8 @@
156156 }
157157
158158
159-std::string qrk::convertToRoman(const char* jp_text, const char* current_input)
159+std::string qrk::convertToRoman(const std::string& jp_text,
160+ const std::string& current_input)
160161 {
161162 // 入力候補に対応するローマ字の文字列を生成する
162163 Utf8 created_jp("");
--- trunk/libs/input/convertToJp.h (revision 1804)
+++ trunk/libs/input/convertToJp.h (revision 1805)
@@ -16,7 +16,8 @@
1616 namespace qrk
1717 {
1818 //! 日本語への変換
19- extern std::string convertToJp(const char* raw_text, bool is_roman = true);
19+ extern std::string convertToJp(const std::string& raw_text,
20+ bool is_roman = true);
2021 }
2122
2223 #endif /* !QRK_CONVERT_TO_JP_H */
--- trunk/libs/input/convertToRoman.h (revision 1804)
+++ trunk/libs/input/convertToRoman.h (revision 1805)
@@ -16,8 +16,8 @@
1616 namespace qrk
1717 {
1818 //! 日本語のローマ字文字列への変換
19- extern std::string convertToRoman(const char* jp_text,
20- const char* current_intput = "");
19+ extern std::string convertToRoman(const std::string& jp_text,
20+ const std::string& current_intput = "");
2121 }
2222
2323 #endif /* !QRK_CONVERT_TO_ROMAN_H */
--- trunk/libs/input/TestUtf8.cpp (revision 1804)
+++ trunk/libs/input/TestUtf8.cpp (revision 1805)
@@ -72,16 +72,16 @@
7272 void TestUtf8::c_strTest(void)
7373 {
7474 Utf8 actual = Utf8("a");
75- CPPUNIT_ASSERT_EQUAL(string("a"), string(actual.c_str()));
75+ CPPUNIT_ASSERT_EQUAL(string("a"), actual.toStdString());
7676
7777 actual = Utf8("あ");
78- CPPUNIT_ASSERT_EQUAL(string("あ"), string(actual.c_str()));
78+ CPPUNIT_ASSERT_EQUAL(string("あ"), actual.toStdString());
7979
8080 actual = Utf8("あい");
81- CPPUNIT_ASSERT_EQUAL(string("あい"), string(actual.c_str()));
81+ CPPUNIT_ASSERT_EQUAL(string("あい"), actual.toStdString());
8282
8383 actual = Utf8("");
84- CPPUNIT_ASSERT_EQUAL(string(""), string(actual.c_str()));
84+ CPPUNIT_ASSERT_EQUAL(string(""), actual.toStdString());
8585 }
8686
8787
@@ -89,21 +89,21 @@
8989 {
9090 Utf8 actual = Utf8("あい");
9191 actual.pop_back();
92- CPPUNIT_ASSERT_EQUAL(string("あ"), string(actual.c_str()));
92+ CPPUNIT_ASSERT_EQUAL(string("あ"), actual.toStdString());
9393
9494 actual.pop_back();
95- CPPUNIT_ASSERT_EQUAL(string(""), string(actual.c_str()));
95+ CPPUNIT_ASSERT_EQUAL(string(""), actual.toStdString());
9696
9797 actual.pop_back();
98- CPPUNIT_ASSERT_EQUAL(string(""), string(actual.c_str()));
98+ CPPUNIT_ASSERT_EQUAL(string(""), actual.toStdString());
9999
100100
101101 actual = Utf8("わっg");
102102 actual.pop_back();
103- CPPUNIT_ASSERT_EQUAL(string("わっ"), string(actual.c_str()));
103+ CPPUNIT_ASSERT_EQUAL(string("わっ"), actual.toStdString());
104104
105- actual = Utf8(actual.c_str());
106- CPPUNIT_ASSERT_EQUAL(string("わっ"), string(actual.c_str()));
105+ actual = Utf8(actual.toStdString());
106+ CPPUNIT_ASSERT_EQUAL(string("わっ"), actual.toStdString());
107107 }
108108
109109
@@ -110,26 +110,26 @@
110110 void TestUtf8::substrTest(void)
111111 {
112112 Utf8 actual = Utf8("あいう");
113- CPPUNIT_ASSERT_EQUAL(string("あい"), string(actual.substr(0, 2).c_str()));
113+ CPPUNIT_ASSERT_EQUAL(string("あい"), actual.substr(0, 2).toStdString());
114114
115115 actual = Utf8("あいう");
116- CPPUNIT_ASSERT_EQUAL(string("あいう"), string(actual.substr(0, 3).c_str()));
116+ CPPUNIT_ASSERT_EQUAL(string("あいう"), actual.substr(0, 3).toStdString());
117117
118118 actual = Utf8("あいう");
119- CPPUNIT_ASSERT_EQUAL(string("あ"), string(actual.substr(0, 1).c_str()));
119+ CPPUNIT_ASSERT_EQUAL(string("あ"), actual.substr(0, 1).toStdString());
120120
121121 actual = Utf8("あいう");
122- CPPUNIT_ASSERT_EQUAL(string("いう"), string(actual.substr(1, 2).c_str()));
122+ CPPUNIT_ASSERT_EQUAL(string("いう"), actual.substr(1, 2).toStdString());
123123
124124 actual = Utf8("あいう");
125- CPPUNIT_ASSERT_EQUAL(string("う"), string(actual.substr(2, 3).c_str()));
125+ CPPUNIT_ASSERT_EQUAL(string("う"), actual.substr(2, 3).toStdString());
126126
127127 actual = Utf8("aiう");
128- CPPUNIT_ASSERT_EQUAL(string("う"), string(actual.substr(2, 1).c_str()));
128+ CPPUNIT_ASSERT_EQUAL(string("う"), actual.substr(2, 1).toStdString());
129129
130130 actual = Utf8("あiう");
131- CPPUNIT_ASSERT_EQUAL(string("iう"), string(actual.substr(1, 2).c_str()));
131+ CPPUNIT_ASSERT_EQUAL(string("iう"), actual.substr(1, 2).toStdString());
132132
133133 actual = Utf8("");
134- CPPUNIT_ASSERT_EQUAL(string(""), string(actual.substr(0, 0).c_str()));
134+ CPPUNIT_ASSERT_EQUAL(string(""), actual.substr(0, 0).toStdString());
135135 }
--- trunk/libs/input/Utf8.cpp (revision 1804)
+++ trunk/libs/input/Utf8.cpp (revision 1805)
@@ -37,7 +37,6 @@
3737 struct Utf8::pImpl
3838 {
3939 string utf8_text_;
40- string c_string_;
4140 vector<size_t> index_;
4241
4342
@@ -57,9 +56,9 @@
5756 }
5857
5958
60- const char* c_str(void)
59+ string toStdString(void)
6160 {
62- c_string_.clear();
61+ string c_string;
6362
6463 size_t n = index_.size();
6564 for (size_t i = 0; i < n; ++i) {
@@ -66,14 +65,14 @@
6665 size_t index = utf8_index(i);
6766 const unsigned short ch = utf8_text_[index];
6867 if (ch & 0xff00) {
69- c_string_.push_back(ch);
70- c_string_.push_back(utf8_text_[index + 1]);
71- c_string_.push_back(utf8_text_[index + 2]);
68+ c_string.push_back(ch);
69+ c_string.push_back(utf8_text_[index + 1]);
70+ c_string.push_back(utf8_text_[index + 2]);
7271 } else {
73- c_string_.push_back(ch);
72+ c_string.push_back(ch);
7473 }
7574 }
76- return c_string_.c_str();
75+ return c_string;
7776 }
7877 };
7978
@@ -91,7 +90,6 @@
9190 Utf8& Utf8::operator = (const Utf8& rhs)
9291 {
9392 this->pimpl->utf8_text_ = rhs.pimpl->utf8_text_;
94- //this->pimpl->c_string_ = rhs.pimpl->c_string_;
9593 this->pimpl->index_ = rhs.pimpl->index_;
9694
9795 return *this;
@@ -147,9 +145,9 @@
147145 }
148146
149147
150-const char* Utf8::c_str(void)
148+std::string Utf8::toStdString(void)
151149 {
152- return pimpl->c_str();
150+ return pimpl->toStdString();
153151 }
154152
155153
--- trunk/libs/input/Utf8.h (revision 1804)
+++ trunk/libs/input/Utf8.h (revision 1805)
@@ -37,7 +37,7 @@
3737 unsigned short ch(size_t index) const;
3838 unsigned short operator[](size_t index);
3939
40- const char* c_str(void);
40+ std::string toStdString(void);
4141
4242 Utf8 substr(size_t first_index, size_t n);
4343
--- trunk/programs/UrgViewer/UrgViewerWindow.cpp (revision 1804)
+++ trunk/programs/UrgViewer/UrgViewerWindow.cpp (revision 1805)
@@ -27,7 +27,9 @@
2727 #include "LockGuard.h"
2828 #include "log_printf.h"
2929 #include "codedString.h"
30+#include "split.h"
3031 #include <QTimer>
32+#include <QDateTime>
3133 #include <QShortcut>
3234 #include <QMessageBox>
3335 #include <QSettings>
@@ -75,6 +77,7 @@
7577
7678 QTimer capture_timer_;
7779 long last_timestamp_;
80+ QDateTime last_record_time_;
7881
7982 RangeSensorParameter parameter_;
8083 CaptureSettings* settings_;
@@ -88,6 +91,7 @@
8891 : widget_(widget), urg_(argc, argv), serial_connection_(NULL),
8992 capture_setting_widget_(urg_), connect_thread_(urg_),
9093 draw_intensity_(false), last_timestamp_(InvalidTimestamp),
94+ last_record_time_(QDateTime::currentDateTime()),
9195 settings_(NULL), set_length_view_(false)
9296 {
9397 com_finder_.addBaseName("/dev/ttyACM");
@@ -398,6 +402,14 @@
398402 return;
399403 }
400404
405+#if 0
406+ QDateTime current = QDateTime::currentDateTime();
407+ if (last_record_time_.secsTo(current) >= 60) {
408+ log_printf("%s\n", current.toString().toStdString().c_str());
409+ last_record_time_ = current;
410+ }
411+#endif
412+
401413 // update "scans interval"
402414 int interval_msec = timestamp - last_timestamp_;
403415 if (last_timestamp_ != InvalidTimestamp) {
@@ -538,6 +550,14 @@
538550 pimpl->connect_thread_.setConnectSettings(device, 115200);
539551 pimpl->connect_thread_.start();
540552
553+ vector<string> tokens;
554+ size_t n = split(tokens, device, "/");
555+ if (n > 0) {
556+ string base_name = tokens[n - 1] + "_error_log.txt";
557+ log_setName(base_name.c_str());
558+ //pimpl->urg_draw_widget_.setDrawPeriod(1000);
559+ }
560+
541561 } else {
542562 // 切断
543563 pimpl->disconnectDevice();
旧リポジトリブラウザで表示