提交 dd63bfc0 编写于 作者: G gruminions 提交者: fengqikai1414

tools: cyber_monitor add support for display enum type

上级 f22d1e3a
...@@ -27,6 +27,7 @@ RenderableMessage* GeneralMessage::Child(int lineNo) const { ...@@ -27,6 +27,7 @@ RenderableMessage* GeneralMessage::Child(int lineNo) const {
void GeneralMessage::PrintRepeatedField(const Screen* s, unsigned& lineNo, void GeneralMessage::PrintRepeatedField(const Screen* s, unsigned& lineNo,
int indent, int index, int jumpLines) { int indent, int index, int jumpLines) {
std::ostringstream outStr; std::ostringstream outStr;
std::ios_base::fmtflags old_flags;
const std::string& fieldName = field_->name(); const std::string& fieldName = field_->name();
outStr << fieldName << ": "; outStr << fieldName << ": ";
...@@ -35,29 +36,33 @@ void GeneralMessage::PrintRepeatedField(const Screen* s, unsigned& lineNo, ...@@ -35,29 +36,33 @@ void GeneralMessage::PrintRepeatedField(const Screen* s, unsigned& lineNo,
} }
switch (field_->cpp_type()) { switch (field_->cpp_type()) {
#define OUTPUT_FIELD(CPPTYPE, METHOD) \ #define OUTPUT_FIELD(CPPTYPE, METHOD, PRECISION) \
case google::protobuf::FieldDescriptor::CPPTYPE_##CPPTYPE: \ case google::protobuf::FieldDescriptor::CPPTYPE_##CPPTYPE: \
outStr << std::setprecision(64) << field_->is_repeated() \ old_flags = outStr.flags(); \
outStr << std::fixed << std::setprecision(PRECISION) \
<< field_->is_repeated() \
? reflection_ptr_->GetRepeated##METHOD(*message_ptr_, field_, index) \ ? reflection_ptr_->GetRepeated##METHOD(*message_ptr_, field_, index) \
: reflection_ptr_->Get##METHOD(*message_ptr_, field_); \ : reflection_ptr_->Get##METHOD(*message_ptr_, field_); \
outStr.flags(old_flags); \
break break
OUTPUT_FIELD(INT32, Int32); OUTPUT_FIELD(INT32, Int32, 6);
OUTPUT_FIELD(INT64, Int64); OUTPUT_FIELD(INT64, Int64, 6);
OUTPUT_FIELD(UINT32, UInt32); OUTPUT_FIELD(UINT32, UInt32, 6);
OUTPUT_FIELD(UINT64, UInt64); OUTPUT_FIELD(UINT64, UInt64, 6);
OUTPUT_FIELD(FLOAT, Float); OUTPUT_FIELD(FLOAT, Float, 6);
OUTPUT_FIELD(DOUBLE, Double); OUTPUT_FIELD(DOUBLE, Double, 9);
OUTPUT_FIELD(BOOL, Bool); OUTPUT_FIELD(BOOL, Bool, 6);
#undef OUTPUT_FIELD #undef OUTPUT_FIELD
case google::protobuf::FieldDescriptor::CPPTYPE_STRING: { case google::protobuf::FieldDescriptor::CPPTYPE_STRING: {
std::string scratch; std::string scratch;
const std::string& value = const std::string& value =
field_->is_repeated() ? reflection_ptr_->GetRepeatedStringReference( field_->is_repeated()
*message_ptr_, field_, index, &scratch) ? reflection_ptr_->GetRepeatedStringReference(
: reflection_ptr_->GetStringReference( *message_ptr_, field_, index, &scratch)
*message_ptr_, field_, &scratch); : reflection_ptr_->GetStringReference(*message_ptr_, field_,
&scratch);
outStr << value.substr(jumpLines); outStr << value.substr(jumpLines);
break; break;
} }
...@@ -71,9 +76,9 @@ void GeneralMessage::PrintRepeatedField(const Screen* s, unsigned& lineNo, ...@@ -71,9 +76,9 @@ void GeneralMessage::PrintRepeatedField(const Screen* s, unsigned& lineNo,
const google::protobuf::EnumValueDescriptor* enum_desc = const google::protobuf::EnumValueDescriptor* enum_desc =
field_->enum_type()->FindValueByNumber(enum_value); field_->enum_type()->FindValueByNumber(enum_value);
if (enum_desc != nullptr) { if (enum_desc != nullptr) {
outStr << enum_desc->name() << " " << enum_value; outStr << enum_desc->name();
} else { } else {
outStr << enum_value << " " << enum_value; outStr << enum_value;
} }
break; break;
} }
...@@ -81,11 +86,10 @@ void GeneralMessage::PrintRepeatedField(const Screen* s, unsigned& lineNo, ...@@ -81,11 +86,10 @@ void GeneralMessage::PrintRepeatedField(const Screen* s, unsigned& lineNo,
case google::protobuf::FieldDescriptor::CPPTYPE_MESSAGE: case google::protobuf::FieldDescriptor::CPPTYPE_MESSAGE:
s->AddStr(indent, lineNo++, outStr.str().c_str()); s->AddStr(indent, lineNo++, outStr.str().c_str());
GeneralMessageBase::PrintMessage( GeneralMessageBase::PrintMessage(
this, this, field_->is_repeated()
field_->is_repeated() ? reflection_ptr_->GetRepeatedMessage(*message_ptr_, field_,
? reflection_ptr_->GetRepeatedMessage(*message_ptr_, field_, index)
index) : reflection_ptr_->GetMessage(*message_ptr_, field_),
: reflection_ptr_->GetMessage(*message_ptr_, field_),
s, lineNo, indent + 2, jumpLines + 1); s, lineNo, indent + 2, jumpLines + 1);
outStr.str(""); outStr.str("");
break; break;
...@@ -94,11 +98,10 @@ void GeneralMessage::PrintRepeatedField(const Screen* s, unsigned& lineNo, ...@@ -94,11 +98,10 @@ void GeneralMessage::PrintRepeatedField(const Screen* s, unsigned& lineNo,
s->AddStr(indent, lineNo++, outStr.str().c_str()); s->AddStr(indent, lineNo++, outStr.str().c_str());
} }
GeneralMessage::GeneralMessage( GeneralMessage::GeneralMessage(GeneralMessageBase* parent,
GeneralMessageBase* parent, const google::protobuf::Message* msg,
const google::protobuf::Message* const google::protobuf::Reflection* reflection,
msg, const google::protobuf::Reflection* reflection, const google::protobuf::FieldDescriptor* field)
const google::protobuf::FieldDescriptor* field)
: GeneralMessageBase(parent), : GeneralMessageBase(parent),
itemIndex_(0), itemIndex_(0),
field_(field), field_(field),
...@@ -129,7 +132,7 @@ void GeneralMessage::Render(const Screen* s, int key) { ...@@ -129,7 +132,7 @@ void GeneralMessage::Render(const Screen* s, int key) {
s->AddStr(0, lineNo++, "FrameRatio: "); s->AddStr(0, lineNo++, "FrameRatio: ");
s->AddStr(outStr.str().c_str()); s->AddStr(outStr.str().c_str());
clear(); clear();
if (message_ptr_ && reflection_ptr_) { if (message_ptr_ && reflection_ptr_) {
int size = 0; int size = 0;
...@@ -158,7 +161,8 @@ void GeneralMessage::Render(const Screen* s, int key) { ...@@ -158,7 +161,8 @@ void GeneralMessage::Render(const Screen* s, int key) {
default:; default:;
} }
int lcount = lineCountOfField(*message_ptr_, s->Width(), field_, reflection_ptr_); int lcount =
lineCountOfField(*message_ptr_, s->Width(), field_, reflection_ptr_);
int pageItemCount = s->Height() - lineNo; int pageItemCount = s->Height() - lineNo;
pages_ = lcount / pageItemCount + 1; pages_ = lcount / pageItemCount + 1;
SplitPages(key); SplitPages(key);
......
...@@ -108,6 +108,7 @@ void GeneralMessageBase::PrintMessage(GeneralMessageBase* baseMsg, ...@@ -108,6 +108,7 @@ void GeneralMessageBase::PrintMessage(GeneralMessageBase* baseMsg,
} }
std::ostringstream outStr; std::ostringstream outStr;
std::ios_base::fmtflags old_flags;
for (; i < fields.size(); ++i) { for (; i < fields.size(); ++i) {
const google::protobuf::FieldDescriptor* field = fields[i]; const google::protobuf::FieldDescriptor* field = fields[i];
const std::string& fieldName = field->name(); const std::string& fieldName = field->name();
...@@ -124,18 +125,21 @@ void GeneralMessageBase::PrintMessage(GeneralMessageBase* baseMsg, ...@@ -124,18 +125,21 @@ void GeneralMessageBase::PrintMessage(GeneralMessageBase* baseMsg,
} else { } else {
switch (field->cpp_type()) { switch (field->cpp_type()) {
#define OUTPUT_FIELD(CPPTYPE, METHOD) \ #define OUTPUT_FIELD(CPPTYPE, METHOD, PRECISION) \
case google::protobuf::FieldDescriptor::CPPTYPE_##CPPTYPE: \ case google::protobuf::FieldDescriptor::CPPTYPE_##CPPTYPE: \
outStr << std::setprecision(64) << reflection->Get##METHOD(msg, field); \ old_flags = outStr.flags(); \
outStr << std::fixed << std::setprecision(PRECISION) \
<< reflection->Get##METHOD(msg, field); \
outStr.flags(old_flags); \
break break
OUTPUT_FIELD(INT32, Int32); OUTPUT_FIELD(INT32, Int32, 6);
OUTPUT_FIELD(INT64, Int64); OUTPUT_FIELD(INT64, Int64, 6);
OUTPUT_FIELD(UINT32, UInt32); OUTPUT_FIELD(UINT32, UInt32, 6);
OUTPUT_FIELD(UINT64, UInt64); OUTPUT_FIELD(UINT64, UInt64, 6);
OUTPUT_FIELD(FLOAT, Float); OUTPUT_FIELD(FLOAT, Float, 6);
OUTPUT_FIELD(DOUBLE, Double); OUTPUT_FIELD(DOUBLE, Double, 9);
OUTPUT_FIELD(BOOL, Bool); OUTPUT_FIELD(BOOL, Bool, 6);
#undef OUTPUT_FIELD #undef OUTPUT_FIELD
case google::protobuf::FieldDescriptor::CPPTYPE_ENUM: { case google::protobuf::FieldDescriptor::CPPTYPE_ENUM: {
...@@ -144,9 +148,9 @@ void GeneralMessageBase::PrintMessage(GeneralMessageBase* baseMsg, ...@@ -144,9 +148,9 @@ void GeneralMessageBase::PrintMessage(GeneralMessageBase* baseMsg,
const google::protobuf::EnumValueDescriptor* enum_desc = const google::protobuf::EnumValueDescriptor* enum_desc =
field->enum_type()->FindValueByNumber(enum_value); field->enum_type()->FindValueByNumber(enum_value);
if (enum_desc != nullptr) { if (enum_desc != nullptr) {
outStr << enum_desc->name() << " " << enum_value; outStr << enum_desc->name();
} else { } else {
outStr << enum_value << " " << enum_value; outStr << enum_value;
} }
break; break;
} }
......
cmake_minimum_required(VERSION 2.8.12)
project(cyber_visualizer)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_PREFIX_PATH ${CMAKE_SOURCE_DIR}/third_party/Qt5.5.1/5.5/gcc_64)
find_package(Qt5 REQUIRED COMPONENTS Gui Widgets Core)
set(OUTTER_LIBRARIES
cybertron
cybertron_proto
cybertron_common
sensor_msgs
fastrtps
console_bridge
protobuf
glog
pthread
GL
)
include_directories(.)
file(GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.cc)
file(GLOB HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.h)
file(GLOB UIS ${CMAKE_CURRENT_SOURCE_DIR}/uis/*.ui)
file(GLOB RESOURCE ${CMAKE_CURRENT_SOURCE_DIR}/*.qrc)
qt5_wrap_ui(WRAP_UIS ${UIS})
#qt5_wrap_cpp(MOC widget.h)
qt5_add_resources(RCC ${RESOURCE})
add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS} ${UIS} ${RCC})
target_link_libraries(${PROJECT_NAME} Qt5::Widgets)
target_link_libraries(${PROJECT_NAME} Qt5::Gui)
target_link_libraries(${PROJECT_NAME} Qt5::Core)
target_link_libraries(${PROJECT_NAME} ${OUTTER_LIBRARIES})
target_include_directories(${PROJECT_NAME} PUBLIC ${PROTO_SRC_DIR})
install(TARGETS ${PROJECT_NAME}
DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册