MCPcopy Create free account
hub / github.com/Kitware/VTK / Invoke

Method Invoke

Web/WebAssemblySession/vtkStandaloneSession.cxx:58–118  ·  view source on GitHub ↗

-------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

56
57//-------------------------------------------------------------------------------
58emscripten::val vtkStandaloneSession::Invoke(
59 vtkObjectHandle object, const std::string& methodName, emscripten::val args)
60{
61 if (!args.instanceof (Array))
62 {
63 vtkLog(
64 ERROR, << "Invoke must be called with an objectId: u32, methodName: string, args: Array");
65 return emscripten::val::undefined();
66 }
67 if (auto* manager = static_cast<vtkObjectManager*>(vtkSessionGetManager(this->Session)))
68 {
69 if (auto* dataArray = vtkDataArray::SafeDownCast(manager->GetObjectAtId(object)))
70 {
71 if (methodName == "SetArray")
72 {
73 if (args["length"].as<std::size_t>() == 1)
74 {
75 auto jsArray = args[0];
76 for (const auto& it : IsJSArraySameTypeAsVtkDataArray)
77 {
78 const auto& typeName = it.first;
79 if (jsArray.instanceof (val::global(typeName.c_str())) && it.second(dataArray))
80 {
81 const auto length = jsArray["length"].as<std::size_t>();
82 dataArray->SetNumberOfValues(length);
83 // Copy the data from the JS array to the VTK data array
84 using DispatchT = vtkArrayDispatch::DispatchByValueType<vtkArrayDispatch::AllTypes>;
85 if (!DispatchT::Execute(dataArray, CopyJSArrayToVTKDataArray{}, jsArray))
86 {
87 // Fallback to the default implementation if the DispatchT fails
88 CopyJSArrayToVTKDataArray{}(dataArray, jsArray);
89 }
90 return emscripten::val::undefined();
91 }
92 }
93 vtkLog(ERROR,
94 "Unsupported argument constructed by "
95 << jsArray["constructor"].call<std::string>("toString") << " for "
96 << dataArray->GetClassName() << "::SetArray"
97 << " method.");
98 return emscripten::val::undefined();
99 }
100 else
101 {
102 vtkLog(ERROR, << "vtkDataArray::SetArray expects a list of a single TypedArray");
103 return emscripten::val::undefined();
104 }
105 }
106 }
107 }
108 else
109 {
110 vtkLog(ERROR, "Invalid session: " << this->Session);
111 return emscripten::val::undefined();
112 }
113 vtkSessionJsonImpl argsJsonImpl{ args };
114 auto resultImpl = vtkSessionInvoke(this->Session, object, methodName.c_str(), &argsJsonImpl);
115 auto result = std::move(resultImpl->JsonValue);

Callers

nothing calls this directly

Calls 9

vtkSessionGetManagerFunction · 0.85
globalClass · 0.85
vtkSessionInvokeFunction · 0.85
ExecuteFunction · 0.50
GetObjectAtIdMethod · 0.45
c_strMethod · 0.45
secondMethod · 0.45
SetNumberOfValuesMethod · 0.45
GetClassNameMethod · 0.45

Tested by

no test coverage detected