Commit cb300700 authored by Dženan Zukić's avatar Dženan Zukić

STYLE: improving configuration of uncrustify

Enforces license header and the rest of configuration options. To enable it,
manually run SetupForDevelopment.sh and enable uncrustify during configure.
Also provided is default configuration file to be consulted when a new
option is needed. This file has explanations for all the options.

Also, some source code files have been modified to prevent ugly auto-reformatting.
parent 6d8eef11
......@@ -26,7 +26,6 @@
namespace imstk
{
///
/// \class PbdDihedralConstraint
///
......@@ -45,22 +44,22 @@ public:
///
inline Type getType() const override { return Type::Dihedral; }
///
/// \brief initConstraint
/// p3
/// / | \
/// / | \
/// p0 | p1
/// \ | /
/// \ | /
/// p2
/// \param model
/// \param pIdx1 index of p0
/// \param pIdx2 index of p1
/// \param pIdx3 index of p2
/// \param pIdx4 index of p3
/// \param k stiffness
///
/**
\brief initConstraint
p3
/ | \
/ | \
p0 | p1
\ | /
\ | /
p2
\param model
\param pIdx1 index of p0
\param pIdx2 index of p1
\param pIdx3 index of p2
\param pIdx4 index of p3
\param k stiffness
*/
void initConstraint(PbdModel &model,
const size_t& pIdx1, const size_t& pIdx2,
const size_t& pIdx3, const size_t& pIdx4,
......@@ -75,7 +74,6 @@ public:
double m_restAngle; ///> Rest angle
double m_stiffness; ///> Angular stiffness
};
} //imstk
#endif // imstkPbdDihedralConstraint_h
\ No newline at end of file
#endif // imstkPbdDihedralConstraint_h
......@@ -83,7 +83,7 @@ if(${PROJECT_NAME}_SUPERBUILD)
mark_as_advanced(USE_SYSTEM_${extProj})
endmacro()
option(${PROJECT_NAME}_USE_Uncrustify "Use Uncrustify as a code style beautifier." OFF)
option(${PROJECT_NAME}_USE_Uncrustify "Use Uncrustify as a code style beautifier." ON)
if(${PROJECT_NAME}_USE_Uncrustify)
imstk_define_dependency(Uncrustify)
endif()
......@@ -139,8 +139,48 @@ endif()
# Find external dependencies
#-----------------------------------------------------------------------------
# Uncrustify
find_program(Uncrustify_EXECUTABLE Uncrustify)
find_program(Uncrustify_EXECUTABLE uncrustify)
include(SetupUncrustifyConfig)
if(Uncrustify_EXECUTABLE)
# Add target to run uncrustify
add_custom_target(uncrustifyRun
COMMAND ${Uncrustify_EXECUTABLE}
-c ${CMAKE_CURRENT_LIST_DIR}/Utilities/Uncrustify/iMSTKUncrustify.cfg
-F ${CMAKE_CURRENT_BINARY_DIR}/Uncrustify.list
--no-backup
COMMENT "Run uncrustify - overwrites source files"
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
)
if(BUILD_TESTING)
# Add test to check style using uncrustify
add_test(NAME uncrustifyCheck
COMMAND ${Uncrustify_EXECUTABLE}
-c ${CMAKE_CURRENT_LIST_DIR}/Utilities/Uncrustify/iMSTKUncrustify.cfg
-F ${CMAKE_CURRENT_BINARY_DIR}/Uncrustify.list
--check
COMMENT "Run uncrustify in check mode"
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
)
endif(BUILD_TESTING)
# Write list of files on which to run uncrustify.
# Explicitly write a zero byte file when no source files are specified.
# Otherwise, configure_file() creates a file with a single blank line, and
# uncrustify interprets the blank line as a file name.
file(GLOB_RECURSE UNCRUSTIFY_SOURCE_FILES *.h *.cpp)
set(_uncrustify_list_in ${CMAKE_CURRENT_LIST_DIR}/Utilities/Uncrustify/uncrustify.list.in)
set(_uncrustify_list_out ${CMAKE_CURRENT_BINARY_DIR}/uncrustify.list)
if(UNCRUSTIFY_SOURCE_FILES)
list(SORT UNCRUSTIFY_SOURCE_FILES)
string(REPLACE ";" "\n" UNCRUSTIFY_SOURCE_FILES "${UNCRUSTIFY_SOURCE_FILES}")
configure_file("${_uncrustify_list_in}" "${_uncrustify_list_out}" @ONLY)
else()
file(WRITE "${_uncrustify_list_out}")
endif()
else(Uncrustify_EXECUTABLE)
message(WARNING "uncrustify not found! Cannot run code-style test.")
endif(Uncrustify_EXECUTABLE)
# Assimp
find_package( Assimp REQUIRED )
......
......@@ -133,6 +133,9 @@ The SpatialHashtable class implements a 2D data structure that can map keys to v
**/
```
#### Code style check
You can and should use the `uncrustify` tool to check and/or adjust code style of your files. It is run as part of git's pre-commit hook, as part of test suite invoked by CTest or by building *RUN_TESTS* target in Visual Studio. You can also run it manually by building *uncrustifyRun* target, but in that mode your files will be overwritten so make sure you commit your work beforehand to easily see the style changes automatically made by `uncrustify`.
### Testing your code
*Coming soon - Please refer to the rest of the code in the meantime*
......
......@@ -521,44 +521,47 @@ void testTwoFalcons()
// Print device tracking info (callback)
Logger* logger;
unsigned int displayCpt = 0;
auto postInitFoo = [&logger](Module* module)
{
logger = new Logger(module->getName());
logger->setFrequency(5);
};
auto postUpdateFoo = [&displayCpt, &logger](Module* module)
{
// Print position & velocity
auto client = static_cast<VRPNDeviceClient*>(module);
Vec3d p = client->getPosition();
Vec3d v = client->getVelocity();
std::string message =
" pos = (" + std::to_string(p[0])
+ ", " + std::to_string(p[1])
+ ", " + std::to_string(p[2]) + ") "
+ " vel = (" + std::to_string(v[0])
+ ", " + std::to_string(v[1])
+ ", " + std::to_string(v[2]) + ")";
// Show every 1000 updates in standard
if (++displayCpt > 1000)
auto postInitFoo =
[&logger](Module* module)
{
std::cout << "\r-- " << module->getName() << message << std::flush;
displayCpt = 0;
}
// Asynchronous log
if (logger->readyForLoggingWithFrequency())
logger = new Logger(module->getName());
logger->setFrequency(5);
};
auto postUpdateFoo =
[&displayCpt, &logger](Module* module)
{
logger->log(message, true);
logger->updateLogTime();
}
};
auto postCleanUpFoo = [&logger](Module* module)
{
logger->shutdown();
delete logger;
};
// Print position & velocity
auto client = static_cast<VRPNDeviceClient*>(module);
Vec3d p = client->getPosition();
Vec3d v = client->getVelocity();
std::string message =
" pos = (" + std::to_string(p[0])
+ ", " + std::to_string(p[1])
+ ", " + std::to_string(p[2]) + ") "
+ " vel = (" + std::to_string(v[0])
+ ", " + std::to_string(v[1])
+ ", " + std::to_string(v[2]) + ")";
// Show every 1000 updates in standard
if (++displayCpt > 1000)
{
std::cout << "\r-- " << module->getName() << message << std::flush;
displayCpt = 0;
}
// Asynchronous log
if (logger->readyForLoggingWithFrequency())
{
logger->log(message, true);
logger->updateLogTime();
}
};
auto postCleanUpFoo =
[&logger](Module* module)
{
logger->shutdown();
delete logger;
};
falcon0->setPostInitCallback(postInitFoo);
falcon0->setPostUpdateCallback(postUpdateFoo);
......@@ -2565,10 +2568,11 @@ void testGeometryTransforms()
scene->addSceneObject(cubeObj);
// Rotate the dragon every frame
auto rotateFunc = [&surfaceMesh](Module* module)
{
surfaceMesh->rotate(Vec3d(1., 0, 0), PI / 1000, Geometry::TransformType::ApplyToData);
};
auto rotateFunc =
[&surfaceMesh](Module* module)
{
surfaceMesh->rotate(Vec3d(1., 0, 0), PI / 1000, Geometry::TransformType::ApplyToData);
};
sdk->getSceneManager("testGeometryTransforms")->setPostUpdateCallback(rotateFunc);
// Set Camera configuration
......
......@@ -95,16 +95,17 @@ if [[ ! "$ENABLED" == "true" ]]; then
printf "\tgit config uncrustify.enabled true\n"
printf "\tgit config uncrustify.path path/to/uncrustify #should be in Superbuild/Uncrustify-build/bin\n"
printf "\tgit config uncrustify.conf path/to/config.cfg #should be in Utilities/Uncrustify\n"
exit 1;
fi
if [[ "$SKIP" == "true" ]]; then
printf "\nTo stop skipping style checking (recommended), do:\n"
printf "\tgit config uncrustify.skip false\n\n"
exit 0;
else
printf "\nTo skip style checking (not recommended), do:\n"
printf "\tgit config uncrustify.skip true\n\n"
exit 1;
fi
if [[ "$SKIP" == "true" ]]; then
printf "Skipping style checking. To stop it (recommended), do:\n"
printf "\tgit config uncrustify.skip false\n\n"
exit 0;
else
printf "Running style check on modified files.\n"
printf "To skip style checking (not recommended), do:\n"
printf "\tgit config uncrustify.skip true\n\n"
fi
# check whether the given file matches any of the set extensions
......
/*=========================================================================
Library: iMSTK
Copyright (c) Kitware, Inc. & Center for Modeling, Simulation,
& Imaging in Medicine, Rensselaer Polytechnic Institute.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment