RealSenseDetailCustomization.cpp
Go to the documentation of this file.
2 #include "PCH.h"
3 
4 #if WITH_EDITOR
5 
6 #include "IDetailsView.h"
7 #include "IDetailCustomization.h"
8 #include "IDetailGroup.h"
9 #include "DetailCategoryBuilder.h"
10 #include "DetailLayoutBuilder.h"
11 #include "DetailWidgetRow.h"
12 #include "EditorDirectories.h"
13 #include "DesktopPlatformModule.h"
14 #include "Widgets/Text/STextBlock.h"
15 #include "Widgets/Input/SNumericEntryBox.h"
16 #include "Widgets/Input/SFilePathPicker.h"
17 
18 //
19 // FRealSenseDetailCustomization
20 //
21 
22 void FRealSenseDetailCustomization::Register()
23 {
24  FPropertyEditorModule& PropertyModule = FModuleManager::LoadModuleChecked<FPropertyEditorModule>("PropertyEditor");
25  PropertyModule.RegisterCustomClassLayout("RealSenseInspector", FOnGetDetailCustomizationInstance::CreateStatic(&FRealSenseInspectorCustomization::MakeInstance));
26  //PropertyModule.RegisterCustomPropertyTypeLayout("RealSenseStreamMode", FOnGetPropertyTypeCustomizationInstance::CreateStatic(&FRealSenseStreamModeCustomization::MakeInstance));
27  PropertyModule.NotifyCustomizationModuleChanged(); // LAST
28 }
29 
30 void FRealSenseDetailCustomization::Unregister()
31 {
32  FPropertyEditorModule& PropertyModule = FModuleManager::LoadModuleChecked<FPropertyEditorModule>("PropertyEditor");
33  PropertyModule.UnregisterCustomClassLayout("RealSenseInspector");
34  //PropertyModule.UnregisterCustomPropertyTypeLayout("RealSenseStreamMode");
35 }
36 
37 //
38 // FRealSenseInspectorCustomization
39 //
40 
41 TSharedRef<IDetailCustomization> FRealSenseInspectorCustomization::MakeInstance() { return MakeShareable(new FRealSenseInspectorCustomization); }
42 
43 FRealSenseInspectorCustomization::FRealSenseInspectorCustomization()
44 {
45  DetailLayoutPtr = nullptr;
46  RsDevices.Reset(new rs2::device_list());
47 }
48 
49 void FRealSenseInspectorCustomization::CustomizeDetails(IDetailLayoutBuilder& DetailLayout)
50 {
52  REALSENSE_TRACE(TEXT("FRealSenseInspectorCustomization::CustomizeDetails"));
53 
54  if (!IRealSensePlugin::Get().GetContext()) return;
55 
56  DetailLayoutPtr = &DetailLayout;
57  auto This = this;
58  auto* Category = &DetailLayout.EditCategory("Hardware Inspector");
59  auto ParentWindow = FSlateApplication::Get().FindBestParentWindowHandleForDialogs(nullptr);
60 
61  if (RsDevices->size() == 0)
62  {
63  UpdateDevices();
64  }
65 
66  Category->AddCustomRow(FText::FromString(TEXT("Refresh")))
67  .WholeRowContent()
68  [
69  SNew(SButton)
70  .Text(FText::FromString(TEXT("Refresh")))
71  .OnClicked_Lambda([This]()
72  {
73  This->UpdateDevices();
74  This->DetailLayoutPtr->ForceRefreshDetails();
75  return FReply::Handled();
76  })
77  ]
78  ;
79 
80  for (auto Device : *RsDevices)
81  {
82  FString DevName = uestr(Device.get_info(RS2_CAMERA_INFO_NAME));
83  FString DevSerial = uestr(Device.get_info(RS2_CAMERA_INFO_SERIAL_NUMBER));
84  auto* DeviceGroup = &Category->AddGroup(TEXT("Device"), FText::FromString(DevName));
85 
86  DeviceGroup->AddWidgetRow()
87  .NameContent()
88  [
89  SNew(STextBlock)
90  .Text(FText::FromString(TEXT("Serial Number")))
91  .Font(IDetailLayoutBuilder::GetDetailFont())
92  ]
93  .ValueContent()
94  [
95  SNew(STextBlock)
96  .Text(FText::FromString(DevSerial))
97  .Font(IDetailLayoutBuilder::GetDetailFont())
98  ]
99  ;
100 
101  DeviceGroup->AddWidgetRow()
102  .NameContent()
103  [
104  SNew(SButton)
105  .Text(FText::FromString(TEXT("Load preset")))
106  .OnClicked_Lambda([This, Device, ParentWindow]()
107  {
108  FString Path;
109  if (This->PickFile(Path, ParentWindow, TEXT("Select preset"), TEXT("Preset file|*.json")))
110  {
111  REALSENSE_TRACE(TEXT("Load preset %s"), *Path);
112  if (URealSenseDevice::LoadPreset(Device.get().get(), Path))
113  {
114  This->UpdateDevices();
115  }
116  }
117  return FReply::Handled();
118  })
119  ]
120  ;
121 
122  DeviceGroup->AddWidgetRow()
123  .NameContent()
124  [
125  SNew(SButton)
126  .Text(FText::FromString(TEXT("Save preset")))
127  .OnClicked_Lambda([This, Device, ParentWindow]()
128  {
129  FString Path;
130  if (This->PickFile(Path, ParentWindow, TEXT("Select preset"), TEXT("Preset file|*.json"), true))
131  {
132  REALSENSE_TRACE(TEXT("Save preset %s"), *Path);
133  URealSenseDevice::SavePreset(Device.get().get(), Path);
134  }
135  return FReply::Handled();
136  })
137  ]
138  ;
139 
140  for (auto Sensor : Device.query_sensors())
141  {
142  FString SensorName = uestr(Sensor.get_info(RS2_CAMERA_INFO_NAME));
143  auto* SensorGroup = &DeviceGroup->AddGroup(TEXT("Sensor"), FText::FromString(SensorName));
144 
145  for (int i = 0; i < RS2_OPTION_COUNT; ++i)
146  {
147  const rs2_option Option = (rs2_option)i;
148 
149  if (Sensor.supports(Option))
150  {
151  auto OptionName = uestr(rs2_option_to_string(Option));
152  auto Range = Sensor.get_option_range(Option);
153 
154  auto UniqId = DevName + "_" + SensorName + "_" + OptionName;
155  if (!ValueCache.Contains(UniqId))
156  {
157  auto Value = Sensor.get_option(Option);
158  ValueCache.Add(UniqId, Value);
159  }
160 
161  SensorGroup->AddWidgetRow()
162  .NameContent()
163  [
164  SNew(STextBlock)
165  .Text(FText::FromString(OptionName))
166  .Font(IDetailLayoutBuilder::GetDetailFont())
167  ]
168  .ValueContent()
169  [
170  SNew(SNumericEntryBox<float>)
171  .MinValue(Range.min)
172  .MinSliderValue(Range.min)
173  .MaxValue(Range.max)
174  .MaxSliderValue(Range.max)
175  .AllowSpin(true)
176  .Value_Lambda([This, UniqId]()
177  {
178  return This->ValueCache.Contains(UniqId) ? This->ValueCache[UniqId] : 0;
179  })
180  .OnValueChanged_Lambda([This, Sensor, Option, UniqId, Range](float NewValue)
181  {
182  NewValue = FMath::RoundToFloat(NewValue / Range.step) * Range.step;
183  Sensor.set_option(Option, NewValue);
184  if (This->ValueCache.Contains(UniqId)) This->ValueCache[UniqId] = NewValue; else This->ValueCache.Add(UniqId, NewValue);
185  })
186  ]
187  ;
188  }
189  }
190  }
191  }
192 }
193 
194 void FRealSenseInspectorCustomization::UpdateDevices()
195 {
197  REALSENSE_TRACE(TEXT("FRealSenseInspectorCustomization::UpdateDevices"));
198 
199  rs2::context_ref RsContext(IRealSensePlugin::Get().GetContext()->GetHandle());
200  *RsDevices = RsContext.query_devices();
201 }
202 
203 bool FRealSenseInspectorCustomization::PickFile(FString& OutPath, const void* ParentWindow, const FString& Title, const FString& Filter, bool SaveFlag)
204 {
205  IDesktopPlatform* DesktopPlatform = FDesktopPlatformModule::Get();
206  if (DesktopPlatform)
207  {
208  TArray<FString> OutFiles;
209  if (SaveFlag)
210  {
211  auto DefaultPath = FEditorDirectories::Get().GetLastDirectory(ELastDirectory::GENERIC_SAVE);
212  if (DesktopPlatform->SaveFileDialog(ParentWindow, Title, DefaultPath, TEXT(""), Filter, EFileDialogFlags::None, OutFiles))
213  {
214  OutPath = OutFiles[0];
215  return true;
216  }
217  }
218  else
219  {
220  auto DefaultPath = FEditorDirectories::Get().GetLastDirectory(ELastDirectory::GENERIC_OPEN);
221  if (DesktopPlatform->OpenFileDialog(ParentWindow, Title, DefaultPath, TEXT(""), Filter, EFileDialogFlags::None, OutFiles))
222  {
223  OutPath = OutFiles[0];
224  return true;
225  }
226  }
227  }
228  return false;
229 }
230 
231 #endif // WITH_EDITOR
rs2_option
Defines general configuration controls. These can generally be mapped to camera UVC controls...
Definition: rs_option.h:22
static IRealSensePlugin & Get()
bool SavePreset(const FString &FileName)
const char * rs2_option_to_string(rs2_option option)
Definition: rs.cpp:1265
::sensor_msgs::Range_< std::allocator< void > > Range
Definition: Range.h:75
#define SCOPED_PROFILER
Definition: Rs2Base.h:32
bool LoadPreset(const FString &FileName)
UTexture2D * Get(TUniquePtr< T > &Dtex)
IMGUI_API void Value(const char *prefix, bool b)
Definition: imgui.cpp:9538
#define REALSENSE_TRACE(Format,...)
Definition: Shared.h:21
int i
FString uestr(const char *str)
Definition: Shared.h:38


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:39