Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 0 additions & 70 deletions scripts/filter.cpp.in

This file was deleted.

114 changes: 103 additions & 11 deletions scripts/make_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,130 @@

from pathlib import Path

def make_filter(output_dir: Path, name: str, template_dir: Path) -> None:
header_template_file = f'{template_dir}/filter.hpp.in'
def make_filter(plugin_dir: Path, name: str, template_dir: Path) -> None:

plugin_name = plugin_dir.name
filter_name = f'{name}Filter'
header_template_file = f'{template_dir}/simplnx_filter.hpp.in'
header_file_contents: str
with open(header_template_file, 'r') as header_file:
header_file_contents = header_file.read().replace('@FILTER_NAME@', name).replace('@UUID@', str(uuid.uuid4()))
header_file_contents = header_file.read().replace('@FILTER_NAME@', filter_name).replace('@UUID@', str(uuid.uuid4()))
header_file_contents = header_file_contents.replace('@PLUGIN_NAME_UPPER@', plugin_name.upper())
header_file_contents = header_file_contents.replace('@PLUGIN_NAME@', plugin_name)
header_file_contents = header_file_contents.replace('@PARAMETER_KEYS@', " // THESE NEED TO BE GENERATED\n")

# write contents out to the new target header file
header_target_file = f'{output_dir}/{name}.hpp'
header_target_file = f'{plugin_dir}/src/{plugin_name}/Filters/{name}Filter.hpp'
print(f'Writing Header file: {header_target_file}')
with open(header_target_file, 'w') as header_file:
header_file.write(header_file_contents)

cpp_template_file = f'{template_dir}/filter.cpp.in'
cpp_template_file = f'{template_dir}/simplnx_filter.cpp.in'
cpp_file_contents: str
with open(cpp_template_file, 'r') as cpp_file:
cpp_file_contents = cpp_file.read().replace('@FILTER_NAME@', name)
cpp_file_contents = cpp_file.read().replace('@ALGORITHM_NAME@', name)
cpp_file_contents = cpp_file_contents.replace('@FILTER_NAME@', filter_name)
cpp_file_contents = cpp_file_contents.replace('@PLUGIN_NAME@', plugin_name)
cpp_file_contents = cpp_file_contents.replace('@PARAMETER_KEYS@', " //TODO: THESE NEED TO BE GENERATED\n")
cpp_file_contents = cpp_file_contents.replace('@PARAMETER_INCLUDES@', "\n //TODO: PARAMETER_INCLUDES")
cpp_file_contents = cpp_file_contents.replace('@DEFAULT_TAGS@', "\"\"")
cpp_file_contents = cpp_file_contents.replace('@PARAMETER_DEFS@', "\n //TODO: PARAMETER_DEFS")
cpp_file_contents = cpp_file_contents.replace('@PREFLIGHT_DEFS@', "\n //TODO: PREFLIGHT_DEFS")
cpp_file_contents = cpp_file_contents.replace('@PROPOSED_ACTIONS@', "\n //TODO: PROPOSED_ACTIONS")
cpp_file_contents = cpp_file_contents.replace('@PREFLIGHT_UPDATED_DEFS@', "\n //TODO: PREFLIGHT_UPDATED_DEFS")
cpp_file_contents = cpp_file_contents.replace('@PREFLIGHT_UPDATED_VALUES@', "\n //TODO: PREFLIGHT_UPDATED_VALUES")
cpp_file_contents = cpp_file_contents.replace('@PARAMETER_JSON_CONSTANTS@', "\n //TODO: PARAMETER_JSON_CONSTANTS")
cpp_file_contents = cpp_file_contents.replace('@INPUT_VALUES_DEF@', "\n //TODO: INPUT_VALUES_DEF")
cpp_file_contents = cpp_file_contents.replace('@PARAMETER_JSON_CONVERSION@', "/* This is a NEW filter and not ported so this section does not matter */")

# write contents out to the new target CPP file
cpp_target_file = f'{plugin_dir}/src/{plugin_name}/Filters/{name}Filter.cpp'
print(f'Writing CPP file: {cpp_target_file}')
with open(cpp_target_file, 'w') as cpp_file:
cpp_file.write(cpp_file_contents)

# ***************************************************************************
# Algorithm File Generation
# ***************************************************************************
header_template_file = f'{template_dir}/simplnx_algorithm.hpp.in'
header_file_contents: str
with open(header_template_file, 'r') as header_file:
header_file_contents = header_file.read().replace('@FILTER_NAME@', name).replace('@UUID@', str(uuid.uuid4()))
header_file_contents = header_file_contents.replace('@PLUGIN_NAME_UPPER@', plugin_name.upper())
header_file_contents = header_file_contents.replace('@PLUGIN_NAME@', plugin_name)
header_file_contents = header_file_contents.replace('@PARAMETER_KEYS@', " // THESE NEED TO BE GENERATED\n")
header_file_contents = header_file_contents.replace('@PARAMETER_INCLUDES@', "\n//TODO: PARAMETER_INCLUDES")
header_file_contents = header_file_contents.replace('@INPUT_VALUE_STRUCT_DEF@', "//TODO: INPUT_VALUE_STRUCT_DEF\n")

# write contents out to the new target header file
cpp_target_file = f'{output_dir}/{name}.cpp'
header_target_file = f'{plugin_dir}/src/{plugin_name}/Filters/Algorithms/{name}.hpp'
print(f'Writing Header file: {header_target_file}')
with open(header_target_file, 'w') as header_file:
header_file.write(header_file_contents)

cpp_template_file = f'{template_dir}/simplnx_algorithm.cpp.in'
cpp_file_contents: str
with open(cpp_template_file, 'r') as cpp_file:
cpp_file_contents = cpp_file.read().replace('@FILTER_NAME@', name)

# write contents out to the new target CPP file
cpp_target_file = f'{plugin_dir}/src/{plugin_name}/Filters/Algorithms/{name}.cpp'
print(f'Writing CPP file: {cpp_target_file}')
with open(cpp_target_file, 'w') as cpp_file:
cpp_file.write(cpp_file_contents)

# ***************************************************************************
# Unit test File Generation
# ***************************************************************************
cpp_template_file = f'{template_dir}/simplnx_unit_test.cpp.in'
cpp_file_contents: str
with open(cpp_template_file, 'r') as cpp_file:
cpp_file_contents = cpp_file.read().replace('@FILTER_NAME@', filter_name)
cpp_file_contents = cpp_file_contents.replace('@PARAMETER_INCLUDES@', "\n //TODO: PARAMETER_INCLUDES")
cpp_file_contents = cpp_file_contents.replace('@PLUGIN_NAME@', plugin_name)
cpp_file_contents = cpp_file_contents.replace('@PARAMETER_DEFS@', "\n //TODO: PARAMETER_DEFS")

# write contents out to the new target CPP file
cpp_target_file = f'{plugin_dir}/test/{name}Test.cpp'
print(f'Writing Doc file: {cpp_target_file}')
with open(cpp_target_file, 'w') as cpp_file:
cpp_file.write(cpp_file_contents)


# ***************************************************************************
# Documentation File Generation
# ***************************************************************************
cpp_template_file = f'{template_dir}/simplnx_docs.md.in'
cpp_file_contents: str
with open(cpp_template_file, 'r') as cpp_file:
cpp_file_contents = cpp_file.read().replace('@FILTER_NAME@', name)

# write contents out to the new target CPP file
cpp_target_file = f'{plugin_dir}/docs/{name}Filter.md'
print(f'Writing Doc file: {cpp_target_file}')
with open(cpp_target_file, 'w') as cpp_file:
cpp_file.write(cpp_file_contents)



print(f'===================================================================')
print(f'Do NOT forget to add your filter to the appropriate CMake Files')
print(f'Do NOT forget to add your filter and algorithm to the CMakeLists.txt file at:')
print(f'{plugin_dir}/CMakeLists.txt')
print(f'Update the unit test CMakeLists.txt file at:')
print(f'{plugin_dir}/test/CMakeLists.txt')
print(f'Do NOT forget to update the documentation file when you are done writing the file')
print(f'===================================================================')

def main() -> None:
parser = argparse.ArgumentParser(description='Creates simplnx filter header and implementation skeleton codes')
parser.add_argument('-o', '--output_dir', type=Path, help='Input directory where files will be created')
parser.add_argument('-o', '--plugin_dir', type=Path, help='Plugin Directory to create the filter')
parser.add_argument('-n', '--name', type=str, help='Name of filter')
parser.add_argument('-t', '--template_dir', type=Path, help='Location of template files')

args = parser.parse_args()

print('args:')
print(f' output_dir = \"{args.output_dir}\"')
print(f' plugin_dir = \"{args.plugin_dir}\"')
print(f' name = \"{args.name}\"')
print(f' template_dir = \"{args.template_dir}\"')
print('')
Expand All @@ -48,7 +135,12 @@ def main() -> None:
print(f' THIS WILL OVERWRITE ANY EXISTING FILE')
print(f'===================================================================')

make_filter(args.output_dir, args.name, args.template_dir)
make_filter(args.plugin_dir, args.name, args.template_dir)

if __name__ == '__main__':
main()

# -----------------------------------------------------------------------------
# Example invocation
# python make_filter.py --plugin_dir /Users/mjackson/Workspace1/simplnx/src/Plugins/SimplnxCore --name "ReadNotesFile" --template_dir /Users/mjackson/Workspace1/simplnx/scripts
# -----------------------------------------------------------------------------
42 changes: 42 additions & 0 deletions scripts/simplnx_algorithm.cpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "@FILTER_NAME@.hpp"

#include "simplnx/DataStructure/DataArray.hpp"
#include "simplnx/DataStructure/DataGroup.hpp"

using namespace nx::core;

// -----------------------------------------------------------------------------
@FILTER_NAME@::@FILTER_NAME@(DataStructure& dataStructure, const IFilter::MessageHandler& mesgHandler, const std::atomic_bool& shouldCancel, @FILTER_NAME@InputValues* inputValues)
: m_DataStructure(dataStructure)
, m_InputValues(inputValues)
, m_ShouldCancel(shouldCancel)
, m_MessageHandler(mesgHandler)
{
}

// -----------------------------------------------------------------------------
@FILTER_NAME@::~@FILTER_NAME@() noexcept = default;

// -----------------------------------------------------------------------------
Result<> @FILTER_NAME@::operator()()
{
/**
* This section of the code should contain the actual algorithmic codes that
* will accomplish the goal of the file.
*
* If you can parallelize the code there are a number of examples on how to do that.
* GenerateIPFColors is one example
*
* If you need to determine what kind of array you have (Int32Array, Float32Array, etc)
* look to the ExecuteDataFunction() in simplnx/Utilities/FilterUtilities.hpp template
* function to help with that code.
* An Example algorithm class is `CombineAttributeArrays` and `RemoveFlaggedVertices`
*
* There are other utility classes that can help alleviate the amount of code that needs
* to be written.
*
* REMOVE THIS COMMENT BLOCK WHEN YOU ARE FINISHED WITH THE FILTER_HUMAN_NAME
*/

return {};
}
48 changes: 48 additions & 0 deletions scripts/simplnx_algorithm.hpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#pragma once

#include "@PLUGIN_NAME@/@PLUGIN_NAME@_export.hpp"

#include "simplnx/DataStructure/DataPath.hpp"
#include "simplnx/DataStructure/DataStructure.hpp"
#include "simplnx/Filter/IFilter.hpp"
@PARAMETER_INCLUDES@

/**
* This is example code to put in the Execute Method of the filter.
@EXECUTE_EXAMPLE_CODE@
*/

namespace nx::core
{

struct @PLUGIN_NAME_UPPER@_EXPORT @FILTER_NAME@InputValues
{
@INPUT_VALUE_STRUCT_DEF@
};

/**
* @class @FILTER_NAME@
* @brief This algorithm implements support code for the @FILTER_NAME@Filter
*/

class @PLUGIN_NAME_UPPER@_EXPORT @FILTER_NAME@
{
public:
@FILTER_NAME@(DataStructure& dataStructure, const IFilter::MessageHandler& mesgHandler, const std::atomic_bool& shouldCancel, @FILTER_NAME@InputValues* inputValues);
~@FILTER_NAME@() noexcept;

@FILTER_NAME@(const @FILTER_NAME@&) = delete;
@FILTER_NAME@(@FILTER_NAME@&&) noexcept = delete;
@FILTER_NAME@& operator=(const @FILTER_NAME@&) = delete;
@FILTER_NAME@& operator=(@FILTER_NAME@&&) noexcept = delete;

Result<> operator()();

private:
DataStructure& m_DataStructure;
const @FILTER_NAME@InputValues* m_InputValues = nullptr;
const std::atomic_bool& m_ShouldCancel;
const IFilter::MessageHandler& m_MessageHandler;
};

} // namespace complex
35 changes: 35 additions & 0 deletions scripts/simplnx_docs.md.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# INSERT_HUMAN_NAME

## Group (Subgroup)

What group (and possibly subgroup) does the filter belong to

## Description

This **Filter** .....

Images can be used with this:

![](Images/@FILTER_NAME@_1.png)

## Warning

## Notes

## Caveats

% Auto generated parameter table will be inserted here

## Reference


## Example Pipelines


## License & Copyright

Please see the description file distributed with this plugin.

## DREAM3D Mailing Lists

If you need help, need to file a bug report or want to request a new feature, please head over to the [DREAM3DNX-Issues](https://github.com/BlueQuartzSoftware/DREAM3DNX-Issues/discussions) GitHub site where the community of DREAM3D-NX users can help answer your questions.
Loading
Loading