Skip to content

Commit

Permalink
Improve clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
Meakk committed Jan 12, 2025
1 parent b134d54 commit 7b42691
Show file tree
Hide file tree
Showing 28 changed files with 263 additions and 213 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/style-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
- name: C++ Formatting
uses: DoozyX/[email protected]
with:
source: 'library application python plugins examples'
source: 'application examples java library plugins python vtkext webassembly'
extensions: 'h,cxx,in'
exclude: '**/*.py.in'
clangFormatVersion: 14 # Last Ubuntu LTS version (22.04)
clangFormatVersion: 18
- name: Python Formatting
uses: psf/black@stable
with:
Expand Down
2 changes: 1 addition & 1 deletion java/F3DJavaBindings.cxx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Automatically generated headers
#include <app_f3d_F3D_Camera.h>
#include <app_f3d_F3D_Engine.h>
#include <app_f3d_F3D_Scene.h>
#include <app_f3d_F3D_Options.h>
#include <app_f3d_F3D_Scene.h>
#include <app_f3d_F3D_Window.h>

#include <engine.h>
Expand Down
2 changes: 1 addition & 1 deletion library/public/scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class F3D_EXPORT scene
struct load_failure_exception : public exception
{
explicit load_failure_exception(const std::string& what = "")
: exception(what){};
: exception(what) {};
};

///@{
Expand Down
9 changes: 3 additions & 6 deletions library/src/interactor_impl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -699,16 +699,13 @@ interactor& interactor_impl::initCommands()
this->addCommand("decrease_light_intensity",
[&](const std::vector<std::string>&) { this->Internals->IncreaseLightIntensity(true); });

this->addCommand("print_scene_info",
[&](const std::vector<std::string>&)
this->addCommand("print_scene_info", [&](const std::vector<std::string>&)
{ this->Internals->Window.PrintSceneDescription(log::VerboseLevel::INFO); });

this->addCommand("print_coloring_info",
[&](const std::vector<std::string>&)
this->addCommand("print_coloring_info", [&](const std::vector<std::string>&)
{ this->Internals->Window.PrintColoringDescription(log::VerboseLevel::INFO); });

this->addCommand("print_mesh_info",
[&](const std::vector<std::string>&)
this->addCommand("print_mesh_info", [&](const std::vector<std::string>&)
{ this->Internals->Scene.PrintImporterDescription(log::VerboseLevel::INFO); });

this->addCommand("print_options_info",
Expand Down
10 changes: 4 additions & 6 deletions library/testing/TestSDKInteractorDocumentation.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ int TestSDKInteractorDocumentation(int argc, char* argv[])
test.expect<f3d::interactor::does_not_exists_exception>(
"Initial invalid group", [&]() { std::ignore = inter.getBindsForGroup("Invalid"); });

test.expect<f3d::interactor::does_not_exists_exception>("Initial invalid bind", [&]() {
std::ignore = inter.getBindingDocumentation({ mod_t::ANY, "Invalid" });
});
test.expect<f3d::interactor::does_not_exists_exception>("Initial invalid bind",
[&]() { std::ignore = inter.getBindingDocumentation({ mod_t::ANY, "Invalid" }); });
}

// Remove all bindings
Expand All @@ -55,9 +54,8 @@ int TestSDKInteractorDocumentation(int argc, char* argv[])
test.expect<f3d::interactor::does_not_exists_exception>(
"Empty group", [&]() { std::ignore = inter.getBindsForGroup("Camera"); });

test.expect<f3d::interactor::does_not_exists_exception>("Empty bind", [&]() {
std::ignore = inter.getBindingDocumentation({ mod_t::ANY, "5" });
});
test.expect<f3d::interactor::does_not_exists_exception>(
"Empty bind", [&]() { std::ignore = inter.getBindingDocumentation({ mod_t::ANY, "5" }); });
}

// Add a dummy binding
Expand Down
5 changes: 2 additions & 3 deletions library/testing/TestSDKSceneInvalid.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ int TestSDKSceneInvalid(int argc, char* argv[])
"add with invalid default scene file", [&]() { sce.add(invalidDefaultScene); });
test.expect<f3d::scene::load_failure_exception>(
"add with invalid full scene file", [&]() { sce.add(invalidFullScene); });
test.expect<f3d::scene::load_failure_exception>("add with invalid multiple files", [&]() {
sce.add({ validFilename, invalidFullScene, invalidDefaultScene });
});
test.expect<f3d::scene::load_failure_exception>("add with invalid multiple files",
[&]() { sce.add({ validFilename, invalidFullScene, invalidDefaultScene }); });

return test.result();
}
3 changes: 1 addition & 2 deletions python/F3DPythonBindings.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,6 @@ PYBIND11_MODULE(pyf3d, module)
.def_static("set_verbose_level", &f3d::log::setVerboseLevel, py::arg("level"),
py::arg("force_std_err") = false)
.def_static("set_use_coloring", &f3d::log::setUseColoring)
.def_static("print",
[](f3d::log::VerboseLevel& level, const std::string& message)
.def_static("print", [](f3d::log::VerboseLevel& level, const std::string& message)
{ f3d::log::print(level, message); });
}
13 changes: 8 additions & 5 deletions vtkext/private/module/F3DColoringInfoHandler.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void F3DColoringInfoHandler::UpdateColoringInfo(vtkDataSet* dataset, bool useCel
info.Name = arrayName;

vtkDataArray* array = useCellData ? dataset->GetCellData()->GetArray(arrayName.c_str())
: dataset->GetPointData()->GetArray(arrayName.c_str());
: dataset->GetPointData()->GetArray(arrayName.c_str());
if (array)
{
info.MaximumNumberOfComponents =
Expand Down Expand Up @@ -101,7 +101,8 @@ void F3DColoringInfoHandler::UpdateColoringInfo(vtkDataSet* dataset, bool useCel
}

//----------------------------------------------------------------------------
std::optional<F3DColoringInfoHandler::ColoringInfo> F3DColoringInfoHandler::SetCurrentColoring(bool enable, bool useCellData, const std::optional<std::string>& arrayName, bool quiet)
std::optional<F3DColoringInfoHandler::ColoringInfo> F3DColoringInfoHandler::SetCurrentColoring(
bool enable, bool useCellData, const std::optional<std::string>& arrayName, bool quiet)
{
this->CurrentUsingCellData = useCellData;
auto& data =
Expand Down Expand Up @@ -138,15 +139,17 @@ std::optional<F3DColoringInfoHandler::ColoringInfo> F3DColoringInfoHandler::SetC
this->CurrentColoringIter.reset();
if (!quiet)
{
F3DLog::Print(F3DLog::Severity::Warning, "Unknown scalar array: \"" + arrayName.value() + "\"");
F3DLog::Print(
F3DLog::Severity::Warning, "Unknown scalar array: \"" + arrayName.value() + "\"");
}
}
}
return this->GetCurrentColoringInfo();
}

//----------------------------------------------------------------------------
std::optional<F3DColoringInfoHandler::ColoringInfo> F3DColoringInfoHandler::GetCurrentColoringInfo() const
std::optional<F3DColoringInfoHandler::ColoringInfo> F3DColoringInfoHandler::GetCurrentColoringInfo()
const
{
if (this->CurrentColoringIter.has_value())
{
Expand All @@ -162,7 +165,7 @@ void F3DColoringInfoHandler::CycleColoringArray(bool cycleToNonColoring)
this->CurrentUsingCellData ? this->CellDataColoringInfo : this->PointDataColoringInfo;
if (!this->CurrentColoringIter.has_value())
{
if(!data.empty())
if (!data.empty())
{
this->CurrentColoringIter = data.begin();
}
Expand Down
9 changes: 6 additions & 3 deletions vtkext/private/module/F3DColoringInfoHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ class F3DColoringInfoHandler
* @param enable: If coloring should be enabled or not
* @param useCellData: If cell data or point data should be used
* @param arrayName: An optional arrayName to color with
* @param quiet: If true, no log will be done by this method, even when failing to find an array to color with
* @param quiet: If true, no log will be done by this method, even when failing to find an array
* to color with
* @return: current coloring info if any, unset optional otherwise
*/
std::optional<ColoringInfo> SetCurrentColoring(bool enable, bool useCellData, const std::optional<std::string>& arrayName, bool quiet);
std::optional<ColoringInfo> SetCurrentColoring(
bool enable, bool useCellData, const std::optional<std::string>& arrayName, bool quiet);

/**
* Get the current coloring state
Expand All @@ -60,7 +62,8 @@ class F3DColoringInfoHandler
* Cycle the current coloring
* If not coloring, this will try to find an array to color with
* This does not change the cell/point data status
* @param cycleToNonColoring: Control whether to cycle to non coloring after reaching the last array or not
* @param cycleToNonColoring: Control whether to cycle to non coloring after reaching the last
* array or not
*/
void CycleColoringArray(bool cycleToNonColoring);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <vtkMathUtilities.h>
#include <vtkNew.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkTestUtilities.h>
#include <vtkXMLStructuredGridReader.h>
#include <vtkXMLUnstructuredGridReader.h>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <vtkNew.h>
#include <vtkTestUtilities.h>
#include <vtkRenderWindow.h>
#include <vtkTestUtilities.h>
#include <vtkXMLUnstructuredGridReader.h>

#include "vtkF3DGenericImporter.h"
Expand Down
5 changes: 4 additions & 1 deletion vtkext/private/module/vtkF3DExternalRenderWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ class vtkF3DExternalRenderWindow : public vtkGenericOpenGLRenderWindow
/**
* An external context is always considered current.
*/
bool IsCurrent() override { return true; }
bool IsCurrent() override
{
return true;
}

/**
* Trigger rendering. Reimplemented to ensure OpenGL is initialized.
Expand Down
12 changes: 7 additions & 5 deletions vtkext/private/module/vtkF3DGenericImporter.cxx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "vtkF3DGenericImporter.h"

#include "vtkF3DPostProcessFilter.h"
#include "F3DLog.h"
#include "vtkF3DPostProcessFilter.h"

#include <vtkActor.h>
#include <vtkEventForwarderCommand.h>
Expand Down Expand Up @@ -136,11 +136,12 @@ void vtkF3DGenericImporter::ImportActors(vtkRenderer* ren)

// Cast to dataset types
this->Pimpl->ImportedPoints = vtkPolyData::SafeDownCast(this->Pimpl->PostPro->GetOutput(1));
vtkImageData* image = vtkImageData::SafeDownCast(this->Pimpl->PostPro->GetOutput(2));
this->Pimpl->ImportedImage = image->GetNumberOfCells() > 0 ? image : nullptr;
vtkImageData* image = vtkImageData::SafeDownCast(this->Pimpl->PostPro->GetOutput(2));
this->Pimpl->ImportedImage = image->GetNumberOfCells() > 0 ? image : nullptr;

// Recover output description from the reader
this->Pimpl->OutputDescription = vtkF3DGenericImporter::GetDataObjectDescription(this->Pimpl->Reader->GetOutputDataObject(0));
this->Pimpl->OutputDescription =
vtkF3DGenericImporter::GetDataObjectDescription(this->Pimpl->Reader->GetOutputDataObject(0));

// Add filter outputs to mapper inputs
this->Pimpl->PolyDataMapper->SetInputConnection(this->Pimpl->PostPro->GetOutputPort(0));
Expand Down Expand Up @@ -260,7 +261,8 @@ std::string vtkF3DGenericImporter::GetDataObjectDescription(vtkDataObject* objec
bool vtkF3DGenericImporter::UpdateAtTimeValue(double timeValue)
{
assert(this->Pimpl->Reader);
if(!this->Pimpl->PostPro->UpdateTimeStep(timeValue) || !this->Pimpl->Reader->GetOutputDataObject(0))
if (!this->Pimpl->PostPro->UpdateTimeStep(timeValue) ||
!this->Pimpl->Reader->GetOutputDataObject(0))
{
F3DLog::Print(F3DLog::Severity::Warning, "A reader failed to update at a timeValue");
return false;
Expand Down
3 changes: 1 addition & 2 deletions vtkext/private/module/vtkF3DImguiConsole.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ void vtkF3DImguiConsole::ShowConsole()
ImGui::Begin("Console", nullptr, winFlags);

// Log window
const float reservedHeight =
ImGui::GetStyle().ItemSpacing.y + ImGui::GetFrameHeightWithSpacing();
const float reservedHeight = ImGui::GetStyle().ItemSpacing.y + ImGui::GetFrameHeightWithSpacing();
if (ImGui::BeginChild(
"LogRegion", ImVec2(0, -reservedHeight), 0, ImGuiWindowFlags_HorizontalScrollbar))
{
Expand Down
40 changes: 23 additions & 17 deletions vtkext/private/module/vtkF3DImguiObserver.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

namespace
{
ImGuiKey GetImGuiKeyFromKeySym(std::string_view&& keySym)
{
// clang-format off
ImGuiKey GetImGuiKeyFromKeySym(std::string_view&& keySym)
{
// clang-format off
static const std::unordered_map<std::string_view, ImGuiKey> keySymToImGuiKey =
{
{ "Tab", ImGuiKey_Tab },
Expand Down Expand Up @@ -162,17 +162,17 @@ namespace
{ "KP_8", ImGuiKey_Keypad8 },
{ "KP_9", ImGuiKey_Keypad9 }
};
// clang-format on
// clang-format on

auto it = keySymToImGuiKey.find(keySym);

if (it == keySymToImGuiKey.end())
{
return ImGuiKey::ImGuiKey_None;
}
auto it = keySymToImGuiKey.find(keySym);

return it->second;
if (it == keySymToImGuiKey.end())
{
return ImGuiKey::ImGuiKey_None;
}

return it->second;
}
}

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -302,12 +302,18 @@ bool vtkF3DImguiObserver::KeyRelease(vtkObject* caller, unsigned long, void*)
void vtkF3DImguiObserver::InstallObservers(vtkRenderWindowInteractor* interactor)
{
interactor->AddObserver(vtkCommand::MouseMoveEvent, this, &vtkF3DImguiObserver::MouseMove, 2.f);
interactor->AddObserver(vtkCommand::LeftButtonPressEvent, this, &vtkF3DImguiObserver::MouseLeftPress, 2.f);
interactor->AddObserver(vtkCommand::LeftButtonReleaseEvent, this, &vtkF3DImguiObserver::MouseLeftRelease, 2.f);
interactor->AddObserver(vtkCommand::RightButtonPressEvent, this, &vtkF3DImguiObserver::MouseRightPress, 2.f);
interactor->AddObserver(vtkCommand::RightButtonReleaseEvent, this, &vtkF3DImguiObserver::MouseRightRelease, 2.f);
interactor->AddObserver(vtkCommand::MouseWheelForwardEvent, this, &vtkF3DImguiObserver::MouseWheelForward, 2.f);
interactor->AddObserver(vtkCommand::MouseWheelBackwardEvent, this, &vtkF3DImguiObserver::MouseWheelBackward, 2.f);
interactor->AddObserver(
vtkCommand::LeftButtonPressEvent, this, &vtkF3DImguiObserver::MouseLeftPress, 2.f);
interactor->AddObserver(
vtkCommand::LeftButtonReleaseEvent, this, &vtkF3DImguiObserver::MouseLeftRelease, 2.f);
interactor->AddObserver(
vtkCommand::RightButtonPressEvent, this, &vtkF3DImguiObserver::MouseRightPress, 2.f);
interactor->AddObserver(
vtkCommand::RightButtonReleaseEvent, this, &vtkF3DImguiObserver::MouseRightRelease, 2.f);
interactor->AddObserver(
vtkCommand::MouseWheelForwardEvent, this, &vtkF3DImguiObserver::MouseWheelForward, 2.f);
interactor->AddObserver(
vtkCommand::MouseWheelBackwardEvent, this, &vtkF3DImguiObserver::MouseWheelBackward, 2.f);
interactor->AddObserver(vtkCommand::KeyPressEvent, this, &vtkF3DImguiObserver::KeyPress, 2.f);
interactor->AddObserver(vtkCommand::KeyReleaseEvent, this, &vtkF3DImguiObserver::KeyRelease, 2.f);
interactor->AddObserver(vtkCommand::CharEvent, this, &vtkF3DImguiObserver::Char, 2.f);
Expand Down
34 changes: 17 additions & 17 deletions vtkext/private/module/vtkF3DInteractorEventRecorder.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,25 @@ void vtkF3DInteractorEventRecorder::ProcessEvents(
break;

default:
{
int mod = 0;
if (rwi->GetShiftKey())
{
int mod = 0;
if (rwi->GetShiftKey())
{
mod |= ModifierKey::ShiftKey;
}
if (rwi->GetControlKey())
{
mod |= ModifierKey::ControlKey;
}
if (rwi->GetAltKey())
{
mod |= ModifierKey::AltKey;
}
self->WriteEvent(vtkCommand::GetStringFromEventId(event), rwi->GetEventPosition(), mod,
rwi->GetKeyCode(), rwi->GetRepeatCount(), rwi->GetKeySym(), callData);

self->OutputStream->flush();
mod |= ModifierKey::ShiftKey;
}
if (rwi->GetControlKey())
{
mod |= ModifierKey::ControlKey;
}
if (rwi->GetAltKey())
{
mod |= ModifierKey::AltKey;
}
self->WriteEvent(vtkCommand::GetStringFromEventId(event), rwi->GetEventPosition(), mod,
rwi->GetKeyCode(), rwi->GetRepeatCount(), rwi->GetKeySym(), callData);

self->OutputStream->flush();
}
}
}
}
Loading

0 comments on commit 7b42691

Please sign in to comment.