diff --git a/docs/api_reference/c_api_index.rst b/docs/api_reference/c_api_index.rst index cd9e5d0..a5d45f3 100644 --- a/docs/api_reference/c_api_index.rst +++ b/docs/api_reference/c_api_index.rst @@ -25,11 +25,11 @@ Functions .. doxygenfunction:: LIBSBMLNETWORK_CPP_NAMESPACE::c_api_isSetModel(SBMLDocument* document) -.. doxygenfunction:: LIBSBMLNETWORK_CPP_NAMESPACE::c_api_autolayout(SBMLDocument* document, const int maxNumConnectedEdges = 3, bool useNameAsTextLabel = true, bool resetLockedElements = false, const char** lockedNodeIds = NULL, const int lockedNodesSize = 0) +.. doxygenfunction:: LIBSBMLNETWORK_CPP_NAMESPACE::c_api_autolayout(SBMLDocument* document, const int maxNumConnectedEdges = 3, bool useNameAsTextLabel = true, bool resetFixedPositionElements = false, const char** fixedPositionNodeIds = NULL, const int fixedPositionNodesSize = 0) .. doxygenfunction:: LIBSBMLNETWORK_CPP_NAMESPACE::c_api_autorender(SBMLDocument *document, const int maxNumConnectedEdges = 3) -.. doxygenfunction:: LIBSBMLNETWORK_CPP_NAMESPACE::c_api_align(SBMLDocument* document, const char **nodeIds, const int nodesSize, const char* alignment, bool ignoreLockedNodes = false) +.. doxygenfunction:: LIBSBMLNETWORK_CPP_NAMESPACE::c_api_align(SBMLDocument* document, const char **nodeIds, const int nodesSize, const char* alignment, bool ignoreFixedPositionNodes = false) .. doxygenfunction:: LIBSBMLNETWORK_CPP_NAMESPACE::c_api_distribute(SBMLDocument* document, const char **nodeIds, const int nodesSize, const char* direction, const double spacing = -1.0) @@ -39,7 +39,7 @@ Functions .. doxygenfunction:: LIBSBMLNETWORK_CPP_NAMESPACE::c_api_createDefaultLayoutFeatures(SBMLDocument* document, const int maxNumConnectedEdges = 3) -.. doxygenfunction:: LIBSBMLNETWORK_CPP_NAMESPACE::c_api_createDefaultLayoutLocations(SBMLDocument* document, const int maxNumConnectedEdges = 3, bool useNameAsTextLabel= true, bool resetLockedElements = false, const char** lockedNodeIds = NULL, const int lockedNodesSize = 0) +.. doxygenfunction:: LIBSBMLNETWORK_CPP_NAMESPACE::c_api_createDefaultLayoutLocations(SBMLDocument* document, const int maxNumConnectedEdges = 3, bool useNameAsTextLabel= true, bool resetFixedPositionElements = false, const char** fixedPositionNodeIds = NULL, const int fixedPositionNodesSize = 0) .. doxygenfunction:: LIBSBMLNETWORK_CPP_NAMESPACE::c_api_createAliasSpeciesGlyph(SBMLDocument* document, const char* speciesId, const char* reactionId, int reactionGlyphIndex, int layoutIndex) diff --git a/docs/api_reference/cpp_api_index.rst b/docs/api_reference/cpp_api_index.rst index f698046..2dd3f9c 100644 --- a/docs/api_reference/cpp_api_index.rst +++ b/docs/api_reference/cpp_api_index.rst @@ -25,11 +25,11 @@ SBMLDocument Functions .. doxygenfunction:: LIBSBMLNETWORK_CPP_NAMESPACE::isSetModel(SBMLDocument* document) -.. doxygenfunction:: LIBSBMLNETWORK_CPP_NAMESPACE::autolayout(SBMLDocument* document, const int maxNumConnectedEdges = 3, bool useNameAsTextLabel = true, bool resetLockedElements = false, std::set lockedNodeIds = std::set()) +.. doxygenfunction:: LIBSBMLNETWORK_CPP_NAMESPACE::autolayout(SBMLDocument* document, const int maxNumConnectedEdges = 3, bool useNameAsTextLabel = true, bool resetFixedPositionElements = false, std::set fixedPositionNodeIds = std::set()) .. doxygenfunction:: LIBSBMLNETWORK_CPP_NAMESPACE::autorender(SBMLDocument* document, const int maxNumConnectedEdges = 3) -.. doxygenfunction:: LIBSBMLNETWORK_CPP_NAMESPACE::align(SBMLDocument* document, std::set nodeIds, const std::string& alignment, const bool ignoreLockedNodes = false) +.. doxygenfunction:: LIBSBMLNETWORK_CPP_NAMESPACE::align(SBMLDocument* document, std::set nodeIds, const std::string& alignment, const bool ignoreFixedPositionNodes = false) .. doxygenfunction:: LIBSBMLNETWORK_CPP_NAMESPACE::distribute(SBMLDocument* document, std::set> nodeIds, const std::string& direction, const double spacing = -1) @@ -106,9 +106,9 @@ Layout Functions .. doxygenfunction:: LIBSBMLNETWORK_CPP_NAMESPACE::removeAllLayouts(SBMLDocument* document) -.. doxygenfunction:: LIBSBMLNETWORK_CPP_NAMESPACE::setDefaultLayoutLocations(SBMLDocument* document, Layout* layout, const int maxNumConnectedEdges = 3, bool useNameAsTextLabel = true, bool resetLockedElements = false, const std::set lockedNodeIds = std::set()) +.. doxygenfunction:: LIBSBMLNETWORK_CPP_NAMESPACE::setDefaultLayoutLocations(SBMLDocument* document, Layout* layout, const int maxNumConnectedEdges = 3, bool useNameAsTextLabel = true, bool resetFixedPositionElements = false, const std::set fixedPositionNodeIds = std::set()) -.. doxygenfunction:: LIBSBMLNETWORK_CPP_NAMESPACE::createDefaultLayoutLocations(SBMLDocument* document, const int maxNumConnectedEdges = 3, bool useNameAsTextLabel = true, bool resetLockedElements = false, const std::set lockedNodeIds = std::set()) +.. doxygenfunction:: LIBSBMLNETWORK_CPP_NAMESPACE::createDefaultLayoutLocations(SBMLDocument* document, const int maxNumConnectedEdges = 3, bool useNameAsTextLabel = true, bool resetFixedPositionElements = false, const std::set fixedPositionNodeIds = std::set()) .. doxygenfunction:: LIBSBMLNETWORK_CPP_NAMESPACE::createDefaultLayoutFeatures(SBMLDocument* document, const int maxNumConnectedEdges = 3) diff --git a/docs/usage.rst b/docs/usage.rst index f80e816..bd4ebec 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -31,7 +31,7 @@ Given the non-deterministic nature of the autolayout algorithm, users can apply network.autolayout() # run autolayout with set parameters - network.autolayout(stiffness=10, gravity=15, use_magnetism=True, use_boundary=True, use_grid=True, locked_nodes=["S1", "S2"]) + network.autolayout(stiffness=10, gravity=15, use_magnetism=True, use_boundary=True, use_grid=True, fixed_position_nodes=["S1", "S2"]) Get/Set Layout and Render data attributes ----------------------------------------- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 74e12f7..0db071d 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -8,19 +8,32 @@ set(SOURCES libsbmlnetwork_render.cpp libsbmlnetwork_render_helpers.cpp libsbmlnetwork_sbmldocument.cpp - libsbmlnetwork_sbmldocument_helpers.cpp libsbmlnetwork_sbmldocument_layout.cpp libsbmlnetwork_layout_render.cpp libsbmlnetwork_sbmldocument_render.cpp - colors/libsbmlnetwork_colors.cpp - styles/libsbmlnetwork_styles.cpp - autolayout/libsbmlnetwork_autolayout.cpp - autolayout/libsbmlnetwork_fruchterman_reingold_algorithm.cpp - autolayout/libsbmlnetwork_autolayout_object_base.cpp - autolayout/libsbmlnetwork_autolayout_node.cpp - autolayout/libsbmlnetwork_autolayout_connection.cpp - autolayout/libsbmlnetwork_autolayout_curve.cpp - autolayout/libsbmlnetwork_autolayout_point.cpp + features/colors/libsbmlnetwork_colors.cpp + features/styles/libsbmlnetwork_styles.cpp + features/autolayout/libsbmlnetwork_autolayout.cpp + features/autolayout/libsbmlnetwork_fruchterman_reingold_algorithm.cpp + features/autolayout/libsbmlnetwork_autolayout_object_base.cpp + features/autolayout/libsbmlnetwork_autolayout_node.cpp + features/autolayout/libsbmlnetwork_autolayout_connection.cpp + features/autolayout/libsbmlnetwork_autolayout_curve.cpp + features/autolayout/libsbmlnetwork_autolayout_point.cpp + features/error_log/libsbmlnetwork_error_log.cpp + features/user_data/libsbmlnetwork_user_data.cpp + features/defaults/libsbmlnetwork_defaults_layout.cpp + features/defaults/libsbmlnetwork_defaults_render.cpp + features/alias_elements/libsbmlnetwork_alias_element.cpp + features/alias_elements/libsbmlnetwork_alias_species.cpp + features/alias_elements/libsbmlnetwork_alias_reaction.cpp + features/hide_elements/libsbmlnetwork_hide_species.cpp + features/align_elements/libsbmlnetwork_align_element.cpp + features/align_elements/libsbmlnetwork_align_species.cpp + features/fix_elements/libsbmlnetwork_fix_element_position.cpp + features/fix_elements/libsbmlnetwork_fix_element_dimensions.cpp + features/set_layout_features/libsbmlnetwork_set_layout_features.cpp + features/update_curves/libsbmlnetwork_update_curves.cpp c_api/libsbmlnetwork_c_api.cpp) ## headers @@ -31,19 +44,32 @@ set(HEADERS libsbmlnetwork_render.h libsbmlnetwork_render_helpers.h libsbmlnetwork_sbmldocument.h - libsbmlnetwork_sbmldocument_helpers.h libsbmlnetwork_sbmldocument_layout.h libsbmlnetwork_layout_render.h libsbmlnetwork_sbmldocument_render.h - colors/libsbmlnetwork_colors.h - styles/libsbmlnetwork_styles.h - autolayout/libsbmlnetwork_autolayout.h - autolayout/libsbmlnetwork_fruchterman_reingold_algorithm.h - autolayout/libsbmlnetwork_autolayout_object_base.h - autolayout/libsbmlnetwork_autolayout_node.h - autolayout/libsbmlnetwork_autolayout_connection.h - autolayout/libsbmlnetwork_autolayout_curve.h - autolayout/libsbmlnetwork_autolayout_point.h + features/colors/libsbmlnetwork_colors.h + features/styles/libsbmlnetwork_styles.h + features/autolayout/libsbmlnetwork_autolayout.h + features/autolayout/libsbmlnetwork_fruchterman_reingold_algorithm.h + features/autolayout/libsbmlnetwork_autolayout_object_base.h + features/autolayout/libsbmlnetwork_autolayout_node.h + features/autolayout/libsbmlnetwork_autolayout_connection.h + features/autolayout/libsbmlnetwork_autolayout_curve.h + features/autolayout/libsbmlnetwork_autolayout_point.h + features/error_log/libsbmlnetwork_error_log.h + features/user_data/libsbmlnetwork_user_data.h + features/defaults/libsbmlnetwork_defaults_layout.h + features/defaults/libsbmlnetwork_defaults_render.h + features/alias_elements/libsbmlnetwork_alias_element.h + features/alias_elements/libsbmlnetwork_alias_species.h + features/alias_elements/libsbmlnetwork_alias_reaction.h + features/hide_elements/libsbmlnetwork_hide_species.h + features/align_elements/libsbmlnetwork_align_element.h + features/align_elements/libsbmlnetwork_align_species.h + features/fix_elements/libsbmlnetwork_fix_element_position.h + features/fix_elements/libsbmlnetwork_fix_element_dimensions.h + features/set_layout_features/libsbmlnetwork_set_layout_features.h + features/update_curves/libsbmlnetwork_update_curves.h c_api/libsbmlnetwork_c_api.h) #### dependencies @@ -87,16 +113,7 @@ if (BUILD_STATIC_LIBS) endif() ### install -file(GLOB SOURCE_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/*.h") -install(FILES ${SOURCE_HEADERS} DESTINATION include/sbmlnetwork COMPONENT libsbmlnetwork_api) -file(GLOB AUTOLAYOUT_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/autolayout/*.h") -install(FILES ${AUTOLAYOUT_HEADERS} DESTINATION include/sbmlnetwork/autolayout COMPONENT libsbmlnetwork_api) -file(GLOB COLORS_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/colors/*.h") -install(FILES ${COLORS_HEADERS} DESTINATION include/sbmlnetwork/colors COMPONENT libsbmlnetwork_api) -file(GLOB STYLES_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/styles/*.h") -install(FILES ${STYLES_HEADERS} DESTINATION include/sbmlnetwork/styles COMPONENT libsbmlnetwork_api) -file(GLOB C_API_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/c_api/*.h") -install(FILES ${C_API_HEADERS} DESTINATION include/sbmlnetwork/c_api COMPONENT libsbmlnetwork_api) +install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ DESTINATION include FILES_MATCHING PATTERN "*.h" PATTERN "bindings" EXCLUDE) if (WIN32) include (InstallRequiredSystemLibraries) endif() diff --git a/src/autolayout/libsbmlnetwork_autolayout.h b/src/autolayout/libsbmlnetwork_autolayout.h deleted file mode 100755 index 01c39b2..0000000 --- a/src/autolayout/libsbmlnetwork_autolayout.h +++ /dev/null @@ -1,86 +0,0 @@ -#ifndef __LIBSBMLNETWORK_AUTOLAYOUT_H_ -#define __LIBSBMLNETWORK_AUTOLAYOUT_H_ - -#ifndef SWIG -#include "sbml/SBMLTypes.h" -#include "sbml/packages/layout/common/LayoutExtensionTypes.h" -#endif - -using namespace libsbml; - -namespace LIBSBMLNETWORK_CPP_NAMESPACE { - -void locateGlyphs(Model* model, Layout* layout, const bool& useNameAsTextLabel = true); - -void locateReactions(Model *model, Layout *layout, const bool& useNameAsTextLabel = false); - -const double getStiffness(Layout *layout); - -void setStiffness(Layout *layout, const double& stiffness); - -void updateStiffness(Layout *layout); - -double getStiffnessAdjustmentFactor(Layout *layout); - -const double getGravity(Layout *layout); - -void setGravity(Layout *layout, const double& gravity); - -void updateGravity(Layout *layout); - -double getGravityAdjustmentFactor(Layout *layout); - -double getCurrentDimensionToDesiredDimensionRatio(Layout *layout); - -double getDesiredDimensionToCurrentDimensionRatio(Layout *layout); - -void randomizeGlyphsLocations(Model* model, Layout* layout); - -void randomizeSpeciesGlyphsLocations(Model* model, Layout* layout, const double& canvasWidth, const double& canvasHeight); - -void randomizeReactionGlyphsLocations(Model* model, Layout* layout, const double& canvasWidth, const double& canvasHeight); - -void randomizeBoundingBoxesPosition(BoundingBox* boundingBox, const double& canvasWidth, const double& canvasHeight); - -void randomizeCurveCenterPoint(Curve* curve, const double& canvasWidth, const double& canvasHeight); - -void setGlyphsDimensions(Model *model, Layout *layout); - -void setSpeciesGlyphDimensions(Model *model, SpeciesGlyph* speciesGlyph); - -void initializeCompartmentGlyphExtents(BoundingBox* compartmentGlyphBoundingBox, BoundingBox* speciesGlyphBoundingBox); - -void updateCompartmentsExtents(Model *model, Layout *layout); - -void updateCompartmentsExtentsUsingTheirElementsExtents(Model *model, Layout *layout); - -void updateCompartmentExtentsUsingItsElementsExtents(BoundingBox* compartmentGlyphBoundingBox, BoundingBox* speciesGlyphBoundingBox); - -void updateCompartmentExtentsUsingItsElementsExtents(BoundingBox* compartmentGlyphBoundingBox, Curve* reactionCurve); - -void updateCompartmentsExtentsUsingTheirPresetAttributes(Layout *layout); - -void updateLayoutDimensions(Layout* layout); - -const bool adjustLayoutDimensions(Layout *layout); - -const double getLayoutDimensionsDesiredWidth(Layout *layout); - -void setLayoutDimensionsDesiredWidth(Layout *layout, const double& width); - -const double getLayoutDimensionsDesiredHeight(Layout *layout); - -void setLayoutDimensionsDesiredHeight(Layout *layout, const double& height); - -const bool autolayoutMayStillConverge(Layout *layout); - -void extractExtents(Layout* layout, double &maxX, double &maxY); - -void extractExtents(BoundingBox* boundingBox, double &minX, double &minY, double &maxX, double &maxY); - -void extractExtents(Curve* reactionCurve, double &minX, double &minY, double &maxX, double &maxY); - -} - -#endif - diff --git a/src/bindings/python/ctypes/libsbmlnetwork.py.cmake b/src/bindings/python/ctypes/libsbmlnetwork.py.cmake index a2a813e..9aa671a 100644 --- a/src/bindings/python/ctypes/libsbmlnetwork.py.cmake +++ b/src/bindings/python/ctypes/libsbmlnetwork.py.cmake @@ -126,15 +126,15 @@ class LibSBMLNetwork: return self.save(file_name) - def autolayout(self, max_num_connected_edges=3, reset_locked_elements=False, locked_nodes=[]): + def autolayout(self, max_num_connected_edges=3, reset_fixed_position_elements=False, fixed_position_nodes=[]): """ checks if a Layout object, a GlobalRenderInformation object, and LocalRenderInformation object does not exists in the SBMLDocument, then adds them to it, and set all the necessary features for them. :Parameters: - max_num_connected_edges (int, optional): an integer (default: 3) that determines the maximum number of connected edges to a node in the autolayout algorithm (will set the criteria for creating alias nodes). - - reset_locked_elements (boolean, optional): a boolean (default: False) that determines whether to reset the locked elements before applying the autolayout algorithm. - - locked_nodes (list of lists or list of strings, optional): a list (default: []) that determines the nodes that should not be moved during the autolayout algorithm. The list contains: + - reset_fixed_position_elements (boolean, optional): a boolean (default: False) that determines whether to reset the fixed position elements before applying the autolayout algorithm. + - fixed_position_nodes (list of lists or list of strings, optional): a list (default: []) that determines the nodes that should not be moved during the autolayout algorithm. The list contains: - a list of lists where each list includes: - 'id' (str): the ID of the node that must not be moved when autolayout algorithm is applied. - 'index' (int): the index of the graphical object associated with the node that must not be moved when autolayout algorithm is applied. @@ -145,22 +145,22 @@ class LibSBMLNetwork: true on success and false if autolayout algorithm was not applied successfully """ - locked_nodes_ptr = None - if locked_nodes is not None: - locked_nodes_ptr = (ctypes.POINTER(ctypes.c_char_p) * len(locked_nodes))() - for i in range(len(locked_nodes)): - locked_node_ptr = (ctypes.c_char_p * 2)() - if isinstance(locked_nodes[i], list) and len(locked_nodes[i]) == 2: - locked_node_ptr[0] = ctypes.c_char_p(str(locked_nodes[i][0]).encode()) - locked_node_ptr[1] = ctypes.c_char_p(str(locked_nodes[i][1]).encode()) - elif isinstance(locked_nodes[i], str): - locked_node_ptr[0] = ctypes.c_char_p(str(locked_nodes[i]).encode()) - locked_node_ptr[1] = ctypes.c_char_p(str(0).encode()) + fixed_position_nodes_ptr = None + if fixed_position_nodes is not None: + fixed_position_nodes_ptr = (ctypes.POINTER(ctypes.c_char_p) * len(fixed_position_nodes))() + for i in range(len(fixed_position_nodes)): + fixed_position_node_ptr = (ctypes.c_char_p * 2)() + if isinstance(fixed_position_nodes[i], list) and len(fixed_position_nodes[i]) == 2: + fixed_position_node_ptr[0] = ctypes.c_char_p(str(fixed_position_nodes[i][0]).encode()) + fixed_position_node_ptr[1] = ctypes.c_char_p(str(fixed_position_nodes[i][1]).encode()) + elif isinstance(fixed_position_nodes[i], str): + fixed_position_node_ptr[0] = ctypes.c_char_p(str(fixed_position_nodes[i]).encode()) + fixed_position_node_ptr[1] = ctypes.c_char_p(str(0).encode()) else: - raise Exception("The locked_nodes parameter should be a list of lists or a list of strings.") - locked_nodes_ptr[i] = locked_node_ptr + raise Exception("The fixed_position_nodes parameter should be a list of lists or a list of strings.") + fixed_position_nodes_ptr[i] = fixed_position_node_ptr - return lib.c_api_autolayout(self.sbml_object, ctypes.c_int(max_num_connected_edges), self.use_name_as_text_label, reset_locked_elements, locked_nodes_ptr, len(locked_nodes)) + return lib.c_api_autolayout(self.sbml_object, ctypes.c_int(max_num_connected_edges), self.use_name_as_text_label, reset_fixed_position_elements, fixed_position_nodes_ptr, len(fixed_position_nodes)) def autorender(self, max_num_connected_edges=3): """ @@ -176,7 +176,7 @@ class LibSBMLNetwork: """ return lib.c_api_autorender(self.sbml_object, ctypes.c_int(max_num_connected_edges)) - def align(self, nodes, alignment="center", ignore_locked_nodes=False): + def align(self, nodes, alignment="center", ignore_fixed_position_nodes=False): """ Aligns the given nodes in the given alignment type form in the given SBMLDocument @@ -188,7 +188,7 @@ class LibSBMLNetwork: - 'index' (int): the index of the graphical object associated with the node that must be aligned. - or a list of node IDs (str) that must be aligned. - alignment (string, optional): a string (default: "center") that determines the type of alignment to be applied ("top", "bottom", "left", "right", "vCenter", "hCenter", "circular") - - ignore_locked_nodes (boolean, optional): a boolean (default: False) that determines whether to ignore the locked nodes during the alignment + - ignore_fixed_position_nodes (boolean, optional): a boolean (default: False) that determines whether to ignore the fixed position nodes during the alignment :Returns: @@ -209,7 +209,7 @@ class LibSBMLNetwork: raise Exception("The nodes parameter should be a list of lists or a list of strings.") nodes_ptr[i] = node_ptr - return lib.c_api_align(self.sbml_object, nodes_ptr, len(nodes), str(alignment).encode(), ignore_locked_nodes) + return lib.c_api_align(self.sbml_object, nodes_ptr, len(nodes), str(alignment).encode(), ignore_fixed_position_nodes) def distribute(self, nodes, direction="horizontal", spacing=-1): """ @@ -402,25 +402,25 @@ class LibSBMLNetwork: """ return lib.c_api_createDefaultLayoutFeatures(self.sbml_object) - def createDefaultLayoutLocations(self, locked_nodes=[]): + def createDefaultLayoutLocations(self, fixed_position_nodes=[]): """ Creates a default Layout object in the given SBMLDocument and sets the locations of all the graphical objects in the Layout object :Parameters: - - locked_nodes (list, optional): a list (default: []) that determines the list of nodes that should not be moved during the autolayout algorithm. + - fixed_position_nodes (list, optional): a list (default: []) that determines the list of nodes that should not be moved during the autolayout algorithm. :Returns: true on success and false if the default Layout object could not be created """ - locked_nodes_ptr = None - if locked_nodes is not None: - locked_nodes_ptr = (ctypes.c_char_p * len(locked_nodes))() - for i in range(len(locked_nodes)): - locked_nodes_ptr[i] = ctypes.c_char_p(locked_nodes[i].encode()) + fixed_position_nodes_ptr = None + if fixed_position_nodes is not None: + fixed_position_nodes_ptr = (ctypes.c_char_p * len(fixed_position_nodes))() + for i in range(len(fixed_position_nodes)): + fixed_position_nodes_ptr[i] = ctypes.c_char_p(fixed_position_nodes[i].encode()) - return lib.c_api_createDefaultLayoutLocations(self.sbml_object, locked_nodes_ptr, len(locked_nodes)) + return lib.c_api_createDefaultLayoutLocations(self.sbml_object, fixed_position_nodes_ptr, len(fixed_position_nodes)) def createAliasSpeciesGlyph(self, species_id, reaction_id, reaction_glyph_index=0, layout_index=0): """ @@ -12468,7 +12468,7 @@ class LibSBMLNetwork: """ self.use_name_as_text_label = use_name_as_text_label if self.layout_is_added: - self.autolayout(locked_nodes=self.getListOfSpeciesIds()) + self.autolayout(fixed_position_nodes=self.getListOfSpeciesIds()) def enableDisplayCompartmentsTextLabel(self, display_compartments_text_label): """ diff --git a/src/bindings/python/ctypes/sbmlnetwork/tests/test_sbml_network.py b/src/bindings/python/ctypes/sbmlnetwork/tests/test_sbml_network.py index de9c442..3ad260f 100644 --- a/src/bindings/python/ctypes/sbmlnetwork/tests/test_sbml_network.py +++ b/src/bindings/python/ctypes/sbmlnetwork/tests/test_sbml_network.py @@ -51,7 +51,7 @@ def test_displayed_texts(self): def test_move_species(self): for network in self.networks: if network.layout_is_added: - network.autolayout(reset_locked_elements=True) + network.autolayout(reset_fixed_position_elements=True) list_of_species_ids = network.getListOfSpeciesIds() horizontal_displacement = 10.0 vertical_displacement = 10.0 @@ -69,7 +69,7 @@ def test_move_species(self): def test_move_species_with_calling_position_functions(self): for network in self.networks: if network.layout_is_added: - network.autolayout(reset_locked_elements=True) + network.autolayout(reset_fixed_position_elements=True) list_of_species_ids = network.getListOfSpeciesIds() horizontal_displacement = 10.0 vertical_displacement = 10.0 @@ -98,7 +98,7 @@ def disabled_test_set_species_dimensions(self): def test_elements_are_bounded_by_compartment(self): for network in self.networks: if network.layout_is_added: - network.autolayout(reset_locked_elements=True) + network.autolayout(reset_fixed_position_elements=True) list_of_species_ids = network.getListOfSpeciesIds() for species_id in list_of_species_ids: self._check_species_is_bounded_by_its_compartment(network, species_id) @@ -109,73 +109,73 @@ def test_elements_are_bounded_by_compartment(self): def test_align_left(self): for network in self.networks: if network.layout_is_added: - network.autolayout(reset_locked_elements=True) + network.autolayout(reset_fixed_position_elements=True) list_of_species_ids = network.getListOfSpeciesIds() x_min = self._get_min_position_x(network, list_of_species_ids) - network.align(list_of_species_ids, 'left', ignore_locked_nodes=True) + network.align(list_of_species_ids, 'left', ignore_fixed_position_nodes=True) for species_id in list_of_species_ids: self.assertAlmostEqual(x_min, network.getX(species_id), 1) def test_align_right(self): for network in self.networks: if network.layout_is_added: - network.autolayout(reset_locked_elements=True) + network.autolayout(reset_fixed_position_elements=True) list_of_species_ids = network.getListOfSpeciesIds() x_max = self._get_max_position_x(network, list_of_species_ids) - network.align(list_of_species_ids, 'right', ignore_locked_nodes=True) + network.align(list_of_species_ids, 'right', ignore_fixed_position_nodes=True) for species_id in list_of_species_ids: self.assertAlmostEqual(x_max, network.getX(species_id), 1) def test_align_hcenter(self): for network in self.networks: if network.layout_is_added: - network.autolayout(reset_locked_elements=True) + network.autolayout(reset_fixed_position_elements=True) list_of_species_ids = network.getListOfSpeciesIds() x_min = self._get_min_position_x(network, list_of_species_ids) x_max = self._get_max_position_x(network, list_of_species_ids) center_x = 0.5 * (x_min + x_max) - network.align(list_of_species_ids, 'hcenter', ignore_locked_nodes=True) + network.align(list_of_species_ids, 'hcenter', ignore_fixed_position_nodes=True) for species_id in list_of_species_ids: self.assertAlmostEqual(center_x, network.getX(species_id), 1) def test_align_top(self): for network in self.networks: if network.layout_is_added: - network.autolayout(reset_locked_elements=True) + network.autolayout(reset_fixed_position_elements=True) list_of_species_ids = network.getListOfSpeciesIds() y_min = self._get_min_position_y(network, list_of_species_ids) - network.align(list_of_species_ids, 'top', ignore_locked_nodes=True) + network.align(list_of_species_ids, 'top', ignore_fixed_position_nodes=True) for species_id in list_of_species_ids: self.assertAlmostEqual(y_min, network.getY(species_id), 1) def test_align_bottom(self): for network in self.networks: if network.layout_is_added: - network.autolayout(reset_locked_elements=True) + network.autolayout(reset_fixed_position_elements=True) list_of_species_ids = network.getListOfSpeciesIds() y_max = self._get_max_position_y(network, list_of_species_ids) - network.align(list_of_species_ids, 'bottom', ignore_locked_nodes=True) + network.align(list_of_species_ids, 'bottom', ignore_fixed_position_nodes=True) for species_id in list_of_species_ids: self.assertAlmostEqual(y_max, network.getY(species_id), 1) def test_align_vcenter(self): for network in self.networks: if network.layout_is_added: - network.autolayout(reset_locked_elements=True) + network.autolayout(reset_fixed_position_elements=True) list_of_species_ids = network.getListOfSpeciesIds() y_min = self._get_min_position_y(network, list_of_species_ids) y_max = self._get_max_position_y(network, list_of_species_ids) center_y = 0.5 * (y_min + y_max) - network.align(list_of_species_ids, 'vcenter', ignore_locked_nodes=True) + network.align(list_of_species_ids, 'vcenter', ignore_fixed_position_nodes=True) for species_id in list_of_species_ids: self.assertAlmostEqual(center_y, network.getY(species_id), 1) def test_align_circular(self): for network in self.networks: if network.layout_is_added: - network.autolayout(reset_locked_elements=True) + network.autolayout(reset_fixed_position_elements=True) list_of_species_ids = network.getListOfSpeciesIds() - network.align(list_of_species_ids, 'circular', ignore_locked_nodes=True) + network.align(list_of_species_ids, 'circular', ignore_fixed_position_nodes=True) radius = self._get_radius_of_positions(network, list_of_species_ids) center_x, center_y = self._get_center_of_positions(network, list_of_species_ids) self.assertAlmostEqual(radius, 50.0 * len(list_of_species_ids), 1) @@ -186,12 +186,12 @@ def test_align_circular(self): def test_curves_direction_towards_species_center(self): for network in self.networks: if network.layout_is_added: - network.autolayout(reset_locked_elements=True) + network.autolayout(reset_fixed_position_elements=True) list_of_reaction_ids = network.getListOfReactionIds() for reaction_id in list_of_reaction_ids: self._check_curves_direction_towards_species_center(network, reaction_id) - def test_autolayout_remember_locked_nodes(self): + def test_autolayout_remember_fixed_position_nodes(self): for network in self.networks: if network.layout_is_added: network.autolayout() diff --git a/src/c_api/libsbmlnetwork_c_api.cpp b/src/c_api/libsbmlnetwork_c_api.cpp index 2404dc6..216d917 100644 --- a/src/c_api/libsbmlnetwork_c_api.cpp +++ b/src/c_api/libsbmlnetwork_c_api.cpp @@ -2,11 +2,11 @@ #include "../libsbmlnetwork_sbmldocument.h" #include "../libsbmlnetwork_sbmldocument_layout.h" #include "../libsbmlnetwork_sbmldocument_render.h" -#include "../libsbmlnetwork_sbmldocument_helpers.h" #include "../libsbmlnetwork_layout_helpers.h" #include "../libsbmlnetwork_render_helpers.h" -#include "../colors/libsbmlnetwork_colors.h" -#include "../styles/libsbmlnetwork_styles.h" +#include "../features/colors/libsbmlnetwork_colors.h" +#include "../features/styles/libsbmlnetwork_styles.h" +#include "../features/align_elements/libsbmlnetwork_align_element.h" extern "C" { @@ -55,25 +55,25 @@ namespace LIBSBMLNETWORK_CPP_NAMESPACE { return isSetModel(document); } - int c_api_autolayout(SBMLDocument *document, const int maxNumConnectedEdges, bool useNameAsTextLabel, bool resetLockedElements, const char ***lockedNodes, const int lockedNodesSize) { - std::set > lockedNodesSet = std::set >(); - if (lockedNodes) { - for (int i = 0; i < lockedNodesSize; i++) { - const char **lockedNode = lockedNodes[i]; - const char *id = lockedNode[0]; - int index = atoi(lockedNode[1]); - lockedNodesSet.insert(std::make_pair(id, index)); + int c_api_autolayout(SBMLDocument *document, const int maxNumConnectedEdges, bool useNameAsTextLabel, bool resetFixedPositionElements, const char ***fixedPositionNodes, const int fixedPositionNodesSize) { + std::set > fixedPositionNodesSet = std::set >(); + if (fixedPositionNodes) { + for (int i = 0; i < fixedPositionNodesSize; i++) { + const char **fixedPositionNode = fixedPositionNodes[i]; + const char *id = fixedPositionNode[0]; + int index = atoi(fixedPositionNode[1]); + fixedPositionNodesSet.insert(std::make_pair(id, index)); } } - return autolayout(document, maxNumConnectedEdges, useNameAsTextLabel, resetLockedElements, lockedNodesSet); + return autolayout(document, maxNumConnectedEdges, useNameAsTextLabel, resetFixedPositionElements, fixedPositionNodesSet); } int c_api_autorender(SBMLDocument *document, const int maxNumConnectedEdges) { return autorender(document, maxNumConnectedEdges); } - int c_api_align(SBMLDocument* document, const char ***nodes, const int nodesSize, const char* alignment, bool ignoreLockedNodes) { + int c_api_align(SBMLDocument* document, const char ***nodes, const int nodesSize, const char* alignment, bool ignorefixedPositionNodes) { std::set > nodesSet = std::set >(); if (nodes) { for (int i = 0; i < nodesSize; i++) { @@ -83,7 +83,7 @@ namespace LIBSBMLNETWORK_CPP_NAMESPACE { nodesSet.insert(std::make_pair(id, index)); } } - return align(document, nodesSet, alignment, ignoreLockedNodes); + return align(document, nodesSet, alignment, ignorefixedPositionNodes); } int c_api_distribute(SBMLDocument* document, const char ***nodes, const int nodesSize, const char* direction, const double spacing) { @@ -113,17 +113,17 @@ namespace LIBSBMLNETWORK_CPP_NAMESPACE { } int c_api_createDefaultLayoutLocations(SBMLDocument* document, const int maxNumConnectedEdges, - bool useNameAsTextLabel, bool resetLockedElements, - const char ***lockedNodes, const int lockedNodesSize) { - std::set > lockedNodesSet = std::set >(); - for (int i = 0; i < lockedNodesSize; i++) { - const char **lockedNode = lockedNodes[i]; - const char *id = lockedNode[0]; - int index = atoi(lockedNode[1]); - lockedNodesSet.insert(std::make_pair(id, index)); + bool useNameAsTextLabel, bool resetFixedPositionElements, + const char ***fixedPositionNodes, const int fixedPositionNodesSize) { + std::set > fixedPositionNodesSet = std::set >(); + for (int i = 0; i < fixedPositionNodesSize; i++) { + const char **fixedPositionNode = fixedPositionNodes[i]; + const char *id = fixedPositionNode[0]; + int index = atoi(fixedPositionNode[1]); + fixedPositionNodesSet.insert(std::make_pair(id, index)); } - return createDefaultLayoutLocations(document, maxNumConnectedEdges, useNameAsTextLabel, resetLockedElements, lockedNodesSet); + return createDefaultLayoutLocations(document, maxNumConnectedEdges, useNameAsTextLabel, resetFixedPositionElements, fixedPositionNodesSet); } int c_api_createAliasSpeciesGlyph(SBMLDocument* document, const char* speciesId, const char* reactionId, int reactionGlyphIndex, int layoutIndex) { @@ -3288,23 +3288,23 @@ namespace LIBSBMLNETWORK_CPP_NAMESPACE { } int c_api_getNumValidAlignmentValues() { - return getValidAlignmentValues().size(); + return align_elements_getValidAlignmentValues().size(); } const char* c_api_getNthValidAlignmentValue(int index) { if (index >= 0 && index < c_api_getNumValidAlignmentValues()) - return strdup(getValidAlignmentValues().at(index).c_str()); + return strdup(align_elements_getValidAlignmentValues().at(index).c_str()); return ""; } int c_api_getNumValidDistributionDirectionValues() { - return getValidDistributionDirectionValues().size(); + return align_elements_getValidDistributionDirectionValues().size(); } const char* c_api_getNthValidDistributionDirectionValue(int index) { if (index >= 0 && index < c_api_getNumValidDistributionDirectionValues()) - return strdup(getValidDistributionDirectionValues().at(index).c_str()); + return strdup(align_elements_getValidDistributionDirectionValues().at(index).c_str()); return ""; } diff --git a/src/c_api/libsbmlnetwork_c_api.h b/src/c_api/libsbmlnetwork_c_api.h index 4bfa95b..b5d193d 100644 --- a/src/c_api/libsbmlnetwork_c_api.h +++ b/src/c_api/libsbmlnetwork_c_api.h @@ -75,12 +75,12 @@ namespace LIBSBMLNETWORK_CPP_NAMESPACE { /// @param document a pointer to the SBMLDocument object. /// @param maxNumConnectedEdges the maximum number of connected edges to a species glyph. /// @param useNameAsTextLabel a variable that determines whether to use the name of the nodes as text labels in the autolayout algorithm. - /// @param resetLockedElements a variable that determines whether to reset the locked elements in the autolayout algorithm. - /// @param lockedNodeIds an array of strings containing the ids of the nodes and the indices of their associated graphical objects that should be locked in the autolayout algorithm. - /// @param lockedNodesSize the size of lockedNodeIds + /// @param resetFixedPositionElements a variable that determines whether to reset the fixed position elements in the autolayout algorithm. + /// @param fixedPositionNodeIds an array of strings containing the ids of the nodes and the indices of their associated graphical objects that must have fixed position in the autolayout algorithm. + /// @param fixedPositionNodesSize the size of fixedPositionNodeIds /// @return integer value indicating success/failure of the function. LIBSBMLNETWORK_EXTERN int c_api_autolayout(SBMLDocument* document, const int maxNumConnectedEdges = 3, bool useNameAsTextLabel = true, - bool resetLockedElements = false, const char ***locked_nodes = NULL, const int lockedNodesSize = 0); + bool resetFixedPositionElements = false, const char ***fixedPositionNodes = NULL, const int fixedPositionNodesSize = 0); /// @brief Create a Render object, add it to the the SBML document, and set all the necessary features for it. /// @param document a pointer to the SBMLDocument object. @@ -93,9 +93,9 @@ namespace LIBSBMLNETWORK_CPP_NAMESPACE { /// @param nodes an array of strings containing the ids of the nodes and their associated graphical objects that should be aligned. /// @param nodesSize the size of nodeIds /// @param alignment determines how to align the nodes. - /// @param ignoreLockedNodes a variable that determines whether to ignore the locked nodes in the autolayout algorithm. + /// @param ignoreFixedPositionNodes a variable that determines whether to ignore the fixed position nodes in the autolayout algorithm. /// @return integer value indicating success/failure of the function. - LIBSBMLNETWORK_EXTERN int c_api_align(SBMLDocument* document, const char ***nodes, const int nodesSize, const char* alignment, bool ignoreLockedNodes = false); + LIBSBMLNETWORK_EXTERN int c_api_align(SBMLDocument* document, const char ***nodes, const int nodesSize, const char* alignment, bool ignoreFixedPositionNodes = false); /// @brief Distribute the nodes position in the SBML document in the given direction. /// @param document a pointer to the SBMLDocument object. @@ -128,12 +128,12 @@ namespace LIBSBMLNETWORK_CPP_NAMESPACE { /// @param useMagnetism a variable that determines whether to use magnetism in the autolayout algorithm. /// @param useGrid a variable that determines whether to use grid restriction in the autolayout algorithm. /// @param useNameAsTextLabel a variable that determines whether to use the name of the nodes as text labels in the autolayout algorithm. - /// @param resetLockedElements a variable that determines whether to reset the locked elements in the autolayout algorithm. - /// @param lockedNodesSize the size of lockedNodeIds - /// @param lockedNodeIds an array of strings containing the ids of the nodes that should be locked in the autolayout algorithm. + /// @param resetFixedPositionElements a variable that determines whether to reset the fixed position elements in the autolayout algorithm. + /// @param fixedPositionNodesSize the size of fixedPositionNodeIds + /// @param fixedPositionNodeIds an array of strings containing the ids of the nodes that must have fixed position in the autolayout algorithm. /// @return integer value indicating success/failure of the function. LIBSBMLNETWORK_EXTERN int c_api_createDefaultLayoutLocations(SBMLDocument* document, const int maxNumConnectedEdges = 3, bool useNameAsTextLabel= true, - bool resetLockedElements = false, const char*** lockedNodeIds = NULL, const int lockedNodesSize = 0); + bool resetFixedPositionElements = false, const char*** fixedPositionNodeIds = NULL, const int fixedPositionNodesSize = 0); /// @brief Create an alias SpeciesGlyph object for Species with the given id and connect all the SpeciesReferences in the ReactionGlyph object with the given id and index that contain Species as a participant to the alias SpeciesGlyph in the Layout object with the given index in the ListOfLayouts of the SBMLDocument. /// @param document a pointer to the SBMLDocument object. diff --git a/src/features/alias_elements/libsbmlnetwork_alias_element.cpp b/src/features/alias_elements/libsbmlnetwork_alias_element.cpp new file mode 100644 index 0000000..4a83900 --- /dev/null +++ b/src/features/alias_elements/libsbmlnetwork_alias_element.cpp @@ -0,0 +1,20 @@ +#include "libsbmlnetwork_alias_element.h" +#include "../../libsbmlnetwork_layout.h" +#include "../../libsbmlnetwork_layout_helpers.h" + +namespace LIBSBMLNETWORK_CPP_NAMESPACE { + + void alias_element_setAliasGraphicalObjectPosition(GraphicalObject* aliasGraphicalObject, GraphicalObject* graphicalObject, const double& padding) { + double x = getPositionX(graphicalObject); + double y = getPositionY(graphicalObject); + if (isSetCurve(aliasGraphicalObject)) { + setPositionX(getCurve(aliasGraphicalObject), x + padding); + setPositionY(getCurve(aliasGraphicalObject), y + padding); + } + else { + setPositionX(getBoundingBox(aliasGraphicalObject), x + padding); + setPositionY(getBoundingBox(aliasGraphicalObject), y + padding); + } + } + +} diff --git a/src/features/alias_elements/libsbmlnetwork_alias_element.h b/src/features/alias_elements/libsbmlnetwork_alias_element.h new file mode 100644 index 0000000..94752be --- /dev/null +++ b/src/features/alias_elements/libsbmlnetwork_alias_element.h @@ -0,0 +1,17 @@ +#ifndef __LIBSBMLNETWORK_ALIAS_ELEMENT_H +#define __LIBSBMLNETWORK_ALIAS_ELEMENT_H + +#ifndef SWIG +#include "sbml/SBMLTypes.h" +#include "sbml/packages/layout/common/LayoutExtensionTypes.h" +#endif + +using namespace libsbml; + +namespace LIBSBMLNETWORK_CPP_NAMESPACE { + + void alias_element_setAliasGraphicalObjectPosition(GraphicalObject* aliasGraphicalObject, GraphicalObject* graphicalObject, const double& padding = 0.0); + +} + +#endif diff --git a/src/features/alias_elements/libsbmlnetwork_alias_reaction.cpp b/src/features/alias_elements/libsbmlnetwork_alias_reaction.cpp new file mode 100644 index 0000000..83386f4 --- /dev/null +++ b/src/features/alias_elements/libsbmlnetwork_alias_reaction.cpp @@ -0,0 +1,72 @@ +#include "libsbmlnetwork_alias_reaction.h" +#include "../../libsbmlnetwork_layout.h" +#include "../../libsbmlnetwork_layout_helpers.h" +#include "../../features/set_layout_features/libsbmlnetwork_set_layout_features.h" +#include "../../features/alias_elements/libsbmlnetwork_alias_element.h" +#include "../../features/alias_elements/libsbmlnetwork_alias_species.h" +#include "../../features/defaults/libsbmlnetwork_defaults_layout.h" + +namespace LIBSBMLNETWORK_CPP_NAMESPACE { + + int alias_element_createAliasReactionGlyph(SBMLDocument* document, Layout* layout, ReactionGlyph* reactionGlyph) { + if (document && reactionGlyph) { + ReactionGlyph* aliasReactionGlyph = alias_element_createAliasReactionGlyph(layout, reactionGlyph); + return alias_element_createAliasSpeciesReferenceGlyphs(document, layout, reactionGlyph, aliasReactionGlyph); + } + + return -1; + } + + ReactionGlyph* alias_element_createAliasReactionGlyph(Layout* layout, ReactionGlyph* reactionGlyph) { + ReactionGlyph* aliasReactionGlyph = NULL; + if (reactionGlyph) { + aliasReactionGlyph = set_layout_features_createReactionGlyph(layout, reactionGlyph->getReactionId()); + alias_element_setAliasGraphicalObjectPosition(aliasReactionGlyph, reactionGlyph, defaults_getAliasReactionGlyphPadding()); + alias_element_setAliasReactionGlyphTextGlyph(layout, aliasReactionGlyph, reactionGlyph); + } + + return aliasReactionGlyph; + } + + void alias_element_setAliasReactionGlyphTextGlyph(Layout* layout, ReactionGlyph* aliasReactionGlyph, ReactionGlyph* reactionGlyph) { + std::vector textGlyphs = getAssociatedTextGlyphsWithGraphicalObject(layout, reactionGlyph); + if (textGlyphs.size()) { + TextGlyph* textGlyph = createAssociatedTextGlyph(layout, aliasReactionGlyph); + setTextGlyphBoundingBox(textGlyph, textGlyphs.at(0)); + } + } + + int alias_element_createAliasSpeciesReferenceGlyphs(SBMLDocument* document, Layout* layout, ReactionGlyph* referenceReactionGlyph, ReactionGlyph* reactionGlyph) { + std::map speciesGlyphAliasSpeciesGlyphIds; + for (unsigned int i = 0; i < referenceReactionGlyph->getNumSpeciesReferenceGlyphs(); i++) { + SpeciesReferenceGlyph *speciesReferenceGlyph = referenceReactionGlyph->getSpeciesReferenceGlyph(i); + SpeciesGlyph *speciesGlyph = layout->getSpeciesGlyph(speciesReferenceGlyph->getSpeciesGlyphId()); + if (speciesGlyph) { + SpeciesGlyph *connectedSpeciesGlyph = NULL; + if (speciesGlyphAliasSpeciesGlyphIds.find(speciesGlyph->getId()) == speciesGlyphAliasSpeciesGlyphIds.end()) + connectedSpeciesGlyph = alias_element_createAliasSpeciesGlyph(layout, speciesGlyph); + else + connectedSpeciesGlyph = layout->getSpeciesGlyph( + speciesGlyphAliasSpeciesGlyphIds[speciesGlyph->getId()]); + if (connectedSpeciesGlyph) { + speciesGlyphAliasSpeciesGlyphIds[speciesGlyph->getId()] = connectedSpeciesGlyph->getId(); + int stoichiometry = getStoichiometryAsInteger( + findSpeciesReference(document->getModel(), layout, referenceReactionGlyph, speciesGlyph)); + for (unsigned int stoichiometryIndex = 0; stoichiometryIndex < stoichiometry; stoichiometryIndex++) + alias_element_createAliasSpeciesReferenceGlyph(reactionGlyph, speciesReferenceGlyph, + connectedSpeciesGlyph->getId(), stoichiometryIndex); + } + } + } + + return -1; + } + + SpeciesReferenceGlyph* alias_element_createAliasSpeciesReferenceGlyph(ReactionGlyph* reactionGlyph, SpeciesReferenceGlyph* referenceSpeciesReferenceGlyph, const std::string& speciesGlyphId, unsigned int stoichiometryIndex) { + SpeciesReferenceGlyph* aliasSpeciesReferenceGlyph = set_layout_features_createSpeciesReferenceGlyph(reactionGlyph, speciesGlyphId, stoichiometryIndex); + aliasSpeciesReferenceGlyph->setRole(referenceSpeciesReferenceGlyph->getRole()); + set_layout_features_setSpeciesReferenceGlyphCurve(aliasSpeciesReferenceGlyph, referenceSpeciesReferenceGlyph); + return aliasSpeciesReferenceGlyph; + } + +} diff --git a/src/features/alias_elements/libsbmlnetwork_alias_reaction.h b/src/features/alias_elements/libsbmlnetwork_alias_reaction.h new file mode 100644 index 0000000..d86c58b --- /dev/null +++ b/src/features/alias_elements/libsbmlnetwork_alias_reaction.h @@ -0,0 +1,25 @@ +#ifndef __LIBSBMLNETWORK_ALIAS_REACTION_H +#define __LIBSBMLNETWORK_ALIAS_REACTION_H + +#ifndef SWIG +#include "sbml/SBMLTypes.h" +#include "sbml/packages/layout/common/LayoutExtensionTypes.h" +#endif + +using namespace libsbml; + +namespace LIBSBMLNETWORK_CPP_NAMESPACE { + +int alias_element_createAliasReactionGlyph(SBMLDocument* document, Layout* layout, ReactionGlyph* reactionGlyph); + +ReactionGlyph* alias_element_createAliasReactionGlyph(Layout* layout, ReactionGlyph* reactionGlyph); + +void alias_element_setAliasReactionGlyphTextGlyph(Layout* layout, ReactionGlyph* aliasReactionGlyph, ReactionGlyph* reactionGlyph); + +int alias_element_createAliasSpeciesReferenceGlyphs(SBMLDocument* document, Layout* layout, ReactionGlyph* referenceReactionGlyph, ReactionGlyph* reactionGlyph); + +SpeciesReferenceGlyph* alias_element_createAliasSpeciesReferenceGlyph(ReactionGlyph* reactionGlyph, SpeciesReferenceGlyph* referenceSpeciesReferenceGlyph, const std::string& speciesGlyphId, unsigned int stoichiometryIndex = 0); + +} + +#endif diff --git a/src/features/alias_elements/libsbmlnetwork_alias_species.cpp b/src/features/alias_elements/libsbmlnetwork_alias_species.cpp new file mode 100644 index 0000000..a5715e6 --- /dev/null +++ b/src/features/alias_elements/libsbmlnetwork_alias_species.cpp @@ -0,0 +1,81 @@ +#include "libsbmlnetwork_alias_species.h" +#include "../../libsbmlnetwork_layout.h" +#include "../../libsbmlnetwork_layout_helpers.h" +#include "../../features/set_layout_features/libsbmlnetwork_set_layout_features.h" +#include "../../features/alias_elements/libsbmlnetwork_alias_element.h" +#include "../../features/defaults/libsbmlnetwork_defaults_layout.h" + +namespace LIBSBMLNETWORK_CPP_NAMESPACE { + +int alias_element_createAliasSpeciesGlyph(Layout* layout, const std::string speciesId, ReactionGlyph* reactionGlyph) { + if (reactionGlyph) { + std::vector speciesGlyphReferences = getSpeciesReferencesAssociatedWithSpecies(layout, reactionGlyph, speciesId); + if (alias_element_canHaveAlias(layout, speciesGlyphReferences)) { + SpeciesGlyph* aliasSpeciesGlyph = alias_element_createAliasSpeciesGlyph(layout, speciesId, speciesGlyphReferences); + if (aliasSpeciesGlyph) { + alias_element_setAliasGraphicalObjectPosition(aliasSpeciesGlyph, reactionGlyph); + alias_element_setAliasSpeciesGlyphDimensions(aliasSpeciesGlyph, reactionGlyph); + alias_element_setAliasSpeciesGlyphTextGlyph(layout, aliasSpeciesGlyph); + return 0; + } + } + } + + return -1; +} + +SpeciesGlyph* alias_element_createAliasSpeciesGlyph(Layout* layout, SpeciesGlyph* speciesGlyph) { + SpeciesGlyph* aliasSpeciesGlyph = NULL; + if (speciesGlyph) { + aliasSpeciesGlyph = set_layout_features_createSpeciesGlyph(layout, speciesGlyph->getSpeciesId()); + alias_element_setAliasGraphicalObjectPosition(aliasSpeciesGlyph, speciesGlyph, defaults_getAliasSpeciesGlyphPadding()); + alias_element_setAliasSpeciesGlyphDimensions(aliasSpeciesGlyph, speciesGlyph); + alias_element_setAliasSpeciesGlyphTextGlyph(layout, aliasSpeciesGlyph); + } + + return aliasSpeciesGlyph; +} + +SpeciesGlyph* alias_element_createAliasSpeciesGlyph(Layout* layout, const std::string& speciesId, std::vector speciesGlyphReferences) { + SpeciesGlyph* aliasSpeciesGlyph = NULL; + if (speciesGlyphReferences.size()) { + aliasSpeciesGlyph = set_layout_features_createSpeciesGlyph(layout, speciesId); + while (speciesGlyphReferences.size()) { + SpeciesReferenceGlyph* speciesReferenceGlyph = speciesGlyphReferences.back(); + speciesReferenceGlyph->setId(getIdOfSpeciesReferenceGlyphConnectedToNewSpeciesGlyph(speciesReferenceGlyph->getId(), speciesReferenceGlyph->getSpeciesGlyphId(), aliasSpeciesGlyph->getId())); + speciesReferenceGlyph->setSpeciesGlyphId(aliasSpeciesGlyph->getId()); + speciesGlyphReferences.pop_back(); + } + } + + return aliasSpeciesGlyph; +} + +const bool alias_element_canHaveAlias(Layout* layout, std::vector connectedSpeciesGlyphReferencesOfReactionGlyph) { + if (connectedSpeciesGlyphReferencesOfReactionGlyph.size()) { + SpeciesGlyph* speciesGlyph = layout->getSpeciesGlyph(connectedSpeciesGlyphReferencesOfReactionGlyph.at(0)->getSpeciesGlyphId()); + std::vector connectedSpeciesGlyphReferencesOfSpeciesGlyph = set_layout_features_getConnectedSpeciesGlyphReferences(layout, speciesGlyph); + if (connectedSpeciesGlyphReferencesOfSpeciesGlyph.size() > connectedSpeciesGlyphReferencesOfReactionGlyph.size()) + return true; + } + + return false; +} + +void alias_element_setAliasSpeciesGlyphDimensions(SpeciesGlyph* aliasSpeciesGlyph, GraphicalObject* graphicalObject) { + double width = defaults_getSpeciesDefaultWidth();; + if (isSpeciesGlyph(graphicalObject)) + width = getDimensionWidth(graphicalObject); + aliasSpeciesGlyph->getBoundingBox()->setWidth(width); + double height = defaults_getSpeciesDefaultHeight(); + if (isSpeciesGlyph(graphicalObject)) + height = getDimensionHeight(graphicalObject); + aliasSpeciesGlyph->getBoundingBox()->setHeight(height); +} + +void alias_element_setAliasSpeciesGlyphTextGlyph(Layout* layout, SpeciesGlyph* aliasSpeciesGlyph) { + TextGlyph* textGlyph = createAssociatedTextGlyph(layout, aliasSpeciesGlyph); + setTextGlyphBoundingBox(textGlyph, aliasSpeciesGlyph); +} + +} diff --git a/src/features/alias_elements/libsbmlnetwork_alias_species.h b/src/features/alias_elements/libsbmlnetwork_alias_species.h new file mode 100644 index 0000000..ee11abc --- /dev/null +++ b/src/features/alias_elements/libsbmlnetwork_alias_species.h @@ -0,0 +1,27 @@ +#ifndef __LIBSBMLNETWORK_ALIAS_SPECIES_H +#define __LIBSBMLNETWORK_ALIAS_SPECIES_H + +#ifndef SWIG +#include "sbml/SBMLTypes.h" +#include "sbml/packages/layout/common/LayoutExtensionTypes.h" +#endif + +using namespace libsbml; + +namespace LIBSBMLNETWORK_CPP_NAMESPACE { + +int alias_element_createAliasSpeciesGlyph(Layout* layout, const std::string speciesId, ReactionGlyph* reactionGlyph); + +SpeciesGlyph* alias_element_createAliasSpeciesGlyph(Layout* layout, SpeciesGlyph* speciesGlyph); + +SpeciesGlyph* alias_element_createAliasSpeciesGlyph(Layout* layout, const std::string& speciesId, std::vector speciesGlyphReferences); + +const bool alias_element_canHaveAlias(Layout* layout, std::vector connectedSpeciesGlyphReferencesOfReactionGlyph); + +void alias_element_setAliasSpeciesGlyphDimensions(SpeciesGlyph* aliasSpeciesGlyph, GraphicalObject* graphicalObject); + +void alias_element_setAliasSpeciesGlyphTextGlyph(Layout* layout, SpeciesGlyph* aliasSpeciesGlyph); + +} + +#endif diff --git a/src/features/align_elements/libsbmlnetwork_align_element.cpp b/src/features/align_elements/libsbmlnetwork_align_element.cpp new file mode 100644 index 0000000..d85bcbc --- /dev/null +++ b/src/features/align_elements/libsbmlnetwork_align_element.cpp @@ -0,0 +1,44 @@ +#include "libsbmlnetwork_align_element.h" +#include "../../libsbmlnetwork_common.h" +#include "../../features/error_log/libsbmlnetwork_error_log.h" + +namespace LIBSBMLNETWORK_CPP_NAMESPACE { + + const bool align_elements_isValidAlignment(const std::string& alignment, SBase* sBase) { + if (isValueValid(alignment, align_elements_getValidAlignmentValues())) + return true; + + error_log_addErrorToLog(sBase, error_log_createErrorMessage(alignment, align_elements_getValidAlignmentValues())); + return false; + } + + const bool align_elements_isValidDistributionDirection(const std::string& direction, SBase* sBase) { + if (isValueValid(direction, align_elements_getValidDistributionDirectionValues())) + return true; + + error_log_addErrorToLog(sBase, error_log_createErrorMessage(direction, align_elements_getValidDistributionDirectionValues())); + return false; + } + + std::vector align_elements_getValidAlignmentValues() { + std::vector alignmentValues; + alignmentValues.push_back("top"); + alignmentValues.push_back("vCenter"); + alignmentValues.push_back("bottom"); + alignmentValues.push_back("left"); + alignmentValues.push_back("hCenter"); + alignmentValues.push_back("right"); + alignmentValues.push_back("circular"); + + return alignmentValues; + } + + std::vector align_elements_getValidDistributionDirectionValues() { + std::vector distributionDirectionValues; + distributionDirectionValues.push_back("horizontal"); + distributionDirectionValues.push_back("vertical"); + + return distributionDirectionValues; + } + +} diff --git a/src/features/align_elements/libsbmlnetwork_align_element.h b/src/features/align_elements/libsbmlnetwork_align_element.h new file mode 100644 index 0000000..4ed6d2d --- /dev/null +++ b/src/features/align_elements/libsbmlnetwork_align_element.h @@ -0,0 +1,22 @@ +#ifndef __LIBSBMLNETWORK_ALIGN_ELEMENT_H +#define __LIBSBMLNETWORK_ALIGN_ELEMENT_H + +#ifndef SWIG +#include "sbml/SBMLTypes.h" +#endif + +using namespace libsbml; + + +namespace LIBSBMLNETWORK_CPP_NAMESPACE { + + const bool align_elements_isValidAlignment(const std::string& alignment, SBase* sBase = NULL); + + const bool align_elements_isValidDistributionDirection(const std::string& direction, SBase* sBase = NULL); + + std::vector align_elements_getValidAlignmentValues(); + + std::vector align_elements_getValidDistributionDirectionValues(); +} + +#endif diff --git a/src/features/align_elements/libsbmlnetwork_align_species.cpp b/src/features/align_elements/libsbmlnetwork_align_species.cpp new file mode 100644 index 0000000..9aa0f5e --- /dev/null +++ b/src/features/align_elements/libsbmlnetwork_align_species.cpp @@ -0,0 +1,355 @@ +#include "libsbmlnetwork_align_species.h" +#include "../../libsbmlnetwork_layout.h" +#include "../../libsbmlnetwork_layout_helpers.h" +#include "../../features/align_elements/libsbmlnetwork_align_element.h" +#include "../../features/error_log/libsbmlnetwork_error_log.h" +#include "../../features/fix_elements/libsbmlnetwork_fix_element_position.h" + +#include +#include + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + +namespace LIBSBMLNETWORK_CPP_NAMESPACE { + + void align_elements_alignGraphicalObjects(Layout* layout, std::vector graphicalObjects, const std::string& alignment, const bool ignoreFixedPositionNodes) { + if (align_elements_isValidAlignment(alignment, layout)) { + if (stringCompare(alignment, "top")) + align_elements_alignGraphicalObjectsToTop(layout, graphicalObjects, ignoreFixedPositionNodes); + else if (stringCompare(alignment, "vCenter")) + align_elements_alignGraphicalObjectsToVerticalCenter(layout, graphicalObjects, ignoreFixedPositionNodes); + else if (stringCompare(alignment, "bottom")) + align_elements_alignGraphicalObjectsToBottom(layout, graphicalObjects, ignoreFixedPositionNodes); + else if (stringCompare(alignment, "left")) + align_elements_alignGraphicalObjectsToLeft(layout, graphicalObjects, ignoreFixedPositionNodes); + else if (stringCompare(alignment, "hCenter")) + align_elements_alignGraphicalObjectsToHorizontalCenter(layout, graphicalObjects, ignoreFixedPositionNodes); + else if (stringCompare(alignment, "right")) + align_elements_alignGraphicalObjectsToRight(layout, graphicalObjects, ignoreFixedPositionNodes); + else if (stringCompare(alignment, "circular") || stringCompare(alignment, "circle")) + align_elements_alignGraphicalObjectsCircularly(layout, graphicalObjects, ignoreFixedPositionNodes); + } + } + + void align_elements_alignGraphicalObjectsToTop(Layout* layout, std::vector graphicalObjects, const bool ignoreFixedPositionNodes) { + try { + double minY = align_elements_getTopAlignmentPosition(graphicalObjects, ignoreFixedPositionNodes); + for (unsigned int i = 0; i < graphicalObjects.size(); i++) + setPositionY(layout, graphicalObjects.at(i), minY); + } + catch (const std::invalid_argument& e) { + error_log_addErrorToLog(layout, e.what()); + } + } + + const double align_elements_getTopAlignmentPosition(std::vector graphicalObjects, const bool ignoreFixedPositionNodes) { + if (ignoreFixedPositionNodes) + return align_elements_getMinPositionY(graphicalObjects); + std::vector fixedPositionGraphicalObjects = fix_elements_getFixedPositionGraphicalObjects(graphicalObjects); + if (fixedPositionGraphicalObjects.size() == 0) + return align_elements_getMinPositionY(graphicalObjects); + else if (fixedPositionGraphicalObjects.size() == 1) + return fixedPositionGraphicalObjects.at(0)->getBoundingBox()->y(); + else + throw std::invalid_argument("error: Multiple graphical objects in your align list have fixed position, so the alignment cannot be applied. Use the ignoreFixedPositionNodes option to ignore fixed position nodes.\n"); + } + + void align_elements_alignGraphicalObjectsToHorizontalCenter(Layout* layout, std::vector graphicalObjects, const bool ignoreFixedPositionNodes) { + try { + double centerX = align_elements_getHorizontalCenterAlignmentPosition(graphicalObjects, ignoreFixedPositionNodes); + for (unsigned int i = 0; i < graphicalObjects.size(); i++) + setPositionX(layout, graphicalObjects.at(i), centerX); + } + catch (const std::invalid_argument& e) { + error_log_addErrorToLog(layout, e.what()); + } + } + + const double align_elements_getHorizontalCenterAlignmentPosition(std::vector graphicalObjects, const bool ignoreFixedPositionNodes) { + if (ignoreFixedPositionNodes) + return 0.5 * (align_elements_getMinPositionX(graphicalObjects) + align_elements_getMaxPositionX(graphicalObjects)); + std::vector fixedPositionGraphicalObjects = fix_elements_getFixedPositionGraphicalObjects(graphicalObjects); + if (fixedPositionGraphicalObjects.size() == 0) + return 0.5 * (align_elements_getMinPositionX(graphicalObjects) + align_elements_getMaxPositionX(graphicalObjects)); + else if (fixedPositionGraphicalObjects.size() == 1) + return fixedPositionGraphicalObjects.at(0)->getBoundingBox()->x(); + else + throw std::invalid_argument("error: Multiple graphical objects in your align list have fixed position, so the alignment cannot be applied. Use the ignoreFixedPositionNodes option to ignore fixed position nodes.\n"); + } + + void align_elements_alignGraphicalObjectsToBottom(Layout* layout, std::vector graphicalObjects, const bool ignoreFixedPositionNodes) { + try { + double maxY = align_elements_getBottomAlignmentPosition(graphicalObjects, ignoreFixedPositionNodes); + for (unsigned int i = 0; i < graphicalObjects.size(); i++) + setPositionY(layout, graphicalObjects.at(i), maxY); + } + catch (const std::invalid_argument& e) { + error_log_addErrorToLog(layout, e.what()); + } + } + + const double align_elements_getBottomAlignmentPosition(std::vector graphicalObjects, const bool ignoreFixedPositionNodes) { + if (ignoreFixedPositionNodes) + return align_elements_getMaxPositionY(graphicalObjects); + std::vector fixedPositionGraphicalObjects = fix_elements_getFixedPositionGraphicalObjects(graphicalObjects); + if (fixedPositionGraphicalObjects.size() == 0) + return align_elements_getMaxPositionY(graphicalObjects); + else if (fixedPositionGraphicalObjects.size() == 1) + return fixedPositionGraphicalObjects.at(0)->getBoundingBox()->y(); + else + throw std::invalid_argument("error: Multiple graphical objects in your align list have fixed position, so the alignment cannot be applied. Use the ignoreFixedPositionNodes option to ignore fixed position nodes.\n"); + } + + void align_elements_alignGraphicalObjectsToLeft(Layout* layout, std::vector graphicalObjects, const bool ignoreFixedPositionNodes) { + try { + double minX = align_elements_getLeftAlignmentPosition(graphicalObjects, ignoreFixedPositionNodes); + for (unsigned int i = 0; i < graphicalObjects.size(); i++) + setPositionX(layout, graphicalObjects.at(i), minX); + } + catch (const std::invalid_argument& e) { + error_log_addErrorToLog(layout, e.what()); + } + } + + const double align_elements_getLeftAlignmentPosition(std::vector graphicalObjects, const bool ignoreFixedPositionNodes) { + if (ignoreFixedPositionNodes) + return align_elements_getMinPositionX(graphicalObjects); + std::vector fixedPositionGraphicalObjects = fix_elements_getFixedPositionGraphicalObjects(graphicalObjects); + if (fixedPositionGraphicalObjects.size() == 0) + return align_elements_getMinPositionX(graphicalObjects); + else if (fixedPositionGraphicalObjects.size() == 1) + return fixedPositionGraphicalObjects.at(0)->getBoundingBox()->x(); + else + throw std::invalid_argument("error: Multiple graphical objects in your align list have fixed position, so the alignment cannot be applied. Use the ignoreFixedPositionNodes option to ignore fixed position nodes.\n"); + } + + void align_elements_alignGraphicalObjectsToVerticalCenter(Layout* layout, std::vector graphicalObjects, const bool ignoreFixedPositionNodes) { + try { + double centerY = align_elements_getVerticalCenterAlignmentPosition(graphicalObjects, ignoreFixedPositionNodes); + for (unsigned int i = 0; i < graphicalObjects.size(); i++) + setPositionY(layout, graphicalObjects.at(i), centerY); + } + catch (const std::invalid_argument& e) { + error_log_addErrorToLog(layout, e.what()); + } + } + + const double align_elements_getVerticalCenterAlignmentPosition(std::vector graphicalObjects, const bool ignoreFixedPositionNodes) { + if (ignoreFixedPositionNodes) + return 0.5 * (align_elements_getMinPositionY(graphicalObjects) + align_elements_getMaxPositionY(graphicalObjects)); + std::vector fixedPositionGraphicalObjects = fix_elements_getFixedPositionGraphicalObjects(graphicalObjects); + if (fixedPositionGraphicalObjects.size() == 0) + return 0.5 * (align_elements_getMinPositionY(graphicalObjects) + align_elements_getMaxPositionY(graphicalObjects)); + else if (fixedPositionGraphicalObjects.size() == 1) + return fixedPositionGraphicalObjects.at(0)->getBoundingBox()->y(); + else + throw std::invalid_argument("error: Multiple graphical objects in your align list have fixed position, so the alignment cannot be applied. Use the ignoreFixedPositionNodes option to ignore fixed position nodes.\n"); + } + + void align_elements_alignGraphicalObjectsToRight(Layout* layout, std::vector graphicalObjects, const bool ignoreFixedPositionNodes) { + try { + double maxX = align_elements_getRightAlignmentPosition(graphicalObjects, ignoreFixedPositionNodes); + for (unsigned int i = 0; i < graphicalObjects.size(); i++) + setPositionX(layout, graphicalObjects.at(i), maxX); + } + catch (const std::invalid_argument& e) { + error_log_addErrorToLog(layout, e.what()); + } + } + + const double align_elements_getRightAlignmentPosition(std::vector graphicalObjects, const bool ignoreFixedPositionNodes) { + if (ignoreFixedPositionNodes) + return align_elements_getMaxPositionX(graphicalObjects); + std::vector fixedPositionGraphicalObjects = fix_elements_getFixedPositionGraphicalObjects(graphicalObjects); + if (fixedPositionGraphicalObjects.size() == 0) + return align_elements_getMaxPositionX(graphicalObjects); + else if (fixedPositionGraphicalObjects.size() == 1) + return fixedPositionGraphicalObjects.at(0)->getBoundingBox()->x(); + else + throw std::invalid_argument("error: Multiple graphical objects in your align list have fixed position, so the alignment cannot be applied. Use the ignoreFixedPositionNodes option to ignore fixed position nodes.\n"); + } + + void align_elements_alignGraphicalObjectsCircularly(Layout* layout, std::vector graphicalObjects, const bool ignoreFixedPositionNodes) { + double radius = graphicalObjects.size() * 50.0; + double angle = 2 * M_PI / graphicalObjects.size(); + double centerX = std::max(radius, 0.5 * (align_elements_getMinCenterX(graphicalObjects) + align_elements_getMaxCenterX(graphicalObjects))); + double centerY = std::max(radius, 0.5 * (align_elements_getMinCenterY(graphicalObjects) + align_elements_getMaxCenterY(graphicalObjects))); + for (unsigned int i = 0; i < graphicalObjects.size(); i++) { + setPositionX(layout, graphicalObjects.at(i), centerX + radius * cos(i * angle) - 0.5 * graphicalObjects.at(i)->getBoundingBox()->width()); + setPositionY(layout, graphicalObjects.at(i), centerY + radius * sin(i * angle) - 0.5 * graphicalObjects.at(i)->getBoundingBox()->height()); + } + } + + void align_elements_distributeGraphicalObjects(Layout* layout, std::vector graphicalObjects, const std::string& direction, const double& spacing) { + if (align_elements_isValidDistributionDirection(direction, layout)) { + if (stringCompare(direction, "horizontal")) + align_elements_distributeGraphicalObjectsHorizontally(layout, graphicalObjects, spacing); + else if (stringCompare(direction, "vertical")) + align_elements_distributeGraphicalObjectsVertically(layout, graphicalObjects, spacing); + } + } + + void align_elements_distributeGraphicalObjectsHorizontally(Layout* layout, std::vector graphicalObjects, const double& spacing) { + if (graphicalObjects.size() < 2) + return; + double minX = align_elements_getMinPositionX(graphicalObjects); + double maxX = align_elements_getMaxPositionX(graphicalObjects); + double minY = align_elements_getMinPositionY(graphicalObjects); + double maxY = align_elements_getMaxPositionY(graphicalObjects); + double distance = align_elements_findDistributionDistance(minX, maxX, graphicalObjects.size(), spacing); + if (graphicalObjects.size() % 2 == 0) { + for (unsigned int i = 0; i < graphicalObjects.size(); i++) { + setPositionX(layout, graphicalObjects.at(i), minX + i * distance); + setPositionY(layout, graphicalObjects.at(i), 0.5 * (minY + maxY)); + } + } + else { + for (unsigned int i = 0; i < graphicalObjects.size(); i++) { + setPositionX(layout, graphicalObjects.at(i), + 0.5 * (minX + maxX) + (i - 0.5 * (graphicalObjects.size() - 1)) * distance); + setPositionY(layout, graphicalObjects.at(i), 0.5 * (minY + maxY)); + } + } + } + + void align_elements_distributeGraphicalObjectsVertically(Layout* layout, std::vector graphicalObjects, const double& spacing) { + if (graphicalObjects.size() < 2) + return; + double minX = align_elements_getMinPositionX(graphicalObjects); + double maxX = align_elements_getMaxPositionX(graphicalObjects); + double minY = align_elements_getMinPositionY(graphicalObjects); + double maxY = align_elements_getMaxPositionY(graphicalObjects); + double distance = align_elements_findDistributionDistance(minY, maxY, graphicalObjects.size(), spacing); + + if (graphicalObjects.size() % 2 == 0) { + for (unsigned int i = 0; i < graphicalObjects.size(); i++) { + setPositionX(layout, graphicalObjects.at(i), 0.5 * (minX + maxX)); + setPositionY(layout, graphicalObjects.at(i), minY + i * distance); + } + } + else { + for (unsigned int i = 0; i < graphicalObjects.size(); i++) { + setPositionX(layout, graphicalObjects.at(i), 0.5 * (minX + maxX)); + setPositionY(layout, graphicalObjects.at(i), + 0.5 * (minY + maxY) + (i - 0.5 * (graphicalObjects.size() - 1)) * distance); + } + } + } + + const double align_elements_findDistributionDistance(const double& minPosition, const double& maxPosition, const unsigned int& numGraphicalObjects, const double& spacing) { + double distance = 0; + if (spacing > 0) + distance = spacing; + else + distance = (maxPosition - minPosition) / (numGraphicalObjects - 1); + + return distance; + } + + const double align_elements_getMinPositionX(std::vector graphicalObjects) { + if (graphicalObjects.size()) { + double minX = INT_MAX; + for (unsigned int i = 0; i < graphicalObjects.size(); i++) + if (graphicalObjects.at(i)->getBoundingBox()->x() < minX) + minX = graphicalObjects.at(i)->getBoundingBox()->x(); + + return minX; + } + + return 0.0; + } + + const double align_elements_getMinPositionY(std::vector graphicalObjects) { + if (graphicalObjects.size()) { + double minY = INT_MAX; + for (unsigned int i = 0; i < graphicalObjects.size(); i++) + if (graphicalObjects.at(i)->getBoundingBox()->y() < minY) + minY = graphicalObjects.at(i)->getBoundingBox()->y(); + + return minY; + } + + return 0.0; + } + + const double align_elements_getMaxPositionX(std::vector graphicalObjects) { + if (graphicalObjects.size()) { + double maxX = INT_MIN; + for (unsigned int i = 0; i < graphicalObjects.size(); i++) + if (graphicalObjects.at(i)->getBoundingBox()->x() > maxX) + maxX = graphicalObjects.at(i)->getBoundingBox()->x(); + + return maxX; + } + + return 0.0; + } + + const double align_elements_getMaxPositionY(std::vector graphicalObjects) { + if (graphicalObjects.size()) { + double maxY = INT_MIN; + for (unsigned int i = 0; i < graphicalObjects.size(); i++) + if (graphicalObjects.at(i)->getBoundingBox()->y() > maxY) + maxY = graphicalObjects.at(i)->getBoundingBox()->y(); + + return maxY; + } + + return 0.0; + } + + const double align_elements_getMinCenterX(std::vector graphicalObjects) { + if (graphicalObjects.size()) { + double minX = INT_MAX; + for (unsigned int i = 0; i < graphicalObjects.size(); i++) + if (graphicalObjects.at(i)->getBoundingBox()->x() + 0.5 * graphicalObjects.at(i)->getBoundingBox()->width() < minX) + minX = graphicalObjects.at(i)->getBoundingBox()->x() + 0.5 * graphicalObjects.at(i)->getBoundingBox()->width(); + + return minX; + } + + return 0.0; + } + + const double align_elements_getMinCenterY(std::vector graphicalObjects) { + if (graphicalObjects.size()) { + double minY = INT_MAX; + for (unsigned int i = 0; i < graphicalObjects.size(); i++) + if (graphicalObjects.at(i)->getBoundingBox()->y() + 0.5 * graphicalObjects.at(i)->getBoundingBox()->height() < minY) + minY = graphicalObjects.at(i)->getBoundingBox()->y() + 0.5 * graphicalObjects.at(i)->getBoundingBox()->height(); + + return minY; + } + + return 0.0; + } + + const double align_elements_getMaxCenterX(std::vector graphicalObjects) { + if (graphicalObjects.size()) { + double maxX = INT_MIN; + for (unsigned int i = 0; i < graphicalObjects.size(); i++) + if (graphicalObjects.at(i)->getBoundingBox()->x() + 0.5 * graphicalObjects.at(i)->getBoundingBox()->width() > maxX) + maxX = graphicalObjects.at(i)->getBoundingBox()->x() + 0.5 * graphicalObjects.at(i)->getBoundingBox()->width(); + + return maxX; + } + + return 0.0; + } + + const double align_elements_getMaxCenterY(std::vector graphicalObjects) { + if (graphicalObjects.size()) { + double maxY = INT_MIN; + for (unsigned int i = 0; i < graphicalObjects.size(); i++) + if (graphicalObjects.at(i)->getBoundingBox()->y() + 0.5 * graphicalObjects.at(i)->getBoundingBox()->height() > maxY) + maxY = graphicalObjects.at(i)->getBoundingBox()->y() + 0.5 * graphicalObjects.at(i)->getBoundingBox()->height(); + + return maxY; + } + + return 0.0; + } + +} \ No newline at end of file diff --git a/src/features/align_elements/libsbmlnetwork_align_species.h b/src/features/align_elements/libsbmlnetwork_align_species.h new file mode 100644 index 0000000..6900db5 --- /dev/null +++ b/src/features/align_elements/libsbmlnetwork_align_species.h @@ -0,0 +1,75 @@ +#ifndef __LIBSBMLNETWORK_ALIGN_SPECIES_H +#define __LIBSBMLNETWORK_ALIGN_SPECIES_H + +#ifndef SWIG +#include "sbml/SBMLTypes.h" +#include "sbml/packages/layout/common/LayoutExtensionTypes.h" +#endif + +using namespace libsbml; + +namespace LIBSBMLNETWORK_CPP_NAMESPACE { + + void align_elements_alignGraphicalObjects(Layout* layout, std::vector graphicalObjects, const std::string& alignment, const bool ignoreFixedPositionNodes); + + void align_elements_alignGraphicalObjectsToTop(Layout* layout, std::vector graphicalObjects, const bool ignoreFixedPositionNodes); + + const double align_elements_getTopAlignmentPosition(std::vector graphicalObjects, const bool ignoreFixedPositionNodes); + + void align_elements_alignGraphicalObjectsToVerticalCenter(Layout* layout, std::vector graphicalObjects, const bool ignoreFixedPositionNodes); + + const double align_elements_getVerticalCenterAlignmentPosition(std::vector graphicalObjects, const bool ignoreFixedPositionNodes); + + void align_elements_alignGraphicalObjectsToBottom(Layout* layout, std::vector graphicalObjects, const bool ignoreFixedPositionNodes); + + const double align_elements_getBottomAlignmentPosition(std::vector graphicalObjects, const bool ignoreFixedPositionNodes); + + void align_elements_alignGraphicalObjectsToLeft(Layout* layout, std::vector graphicalObjects, const bool ignoreFixedPositionNodes); + + const double align_elements_getLeftAlignmentPosition(std::vector graphicalObjects, const bool ignoreFixedPositionNodes); + + void align_elements_alignGraphicalObjectsToHorizontalCenter(Layout* layout, std::vector graphicalObjects, const bool ignoreFixedPositionNodes); + + const double align_elements_getHorizontalCenterAlignmentPosition(std::vector graphicalObjects, const bool ignoreFixedPositionNodes); + + void align_elements_alignGraphicalObjectsToRight(Layout* layout, std::vector graphicalObjects, const bool ignoreFixedPositionNodes); + + const double align_elements_getRightAlignmentPosition(std::vector graphicalObjects, const bool ignoreFixedPositionNodes); + + void align_elements_alignGraphicalObjectsCircularly(Layout* layout, std::vector graphicalObjects, const bool ignoreFixedPositionNodes); + + void align_elements_distributeGraphicalObjects(Layout* layout, std::vector graphicalObjects, const std::string& direction, const double& spacing); + + void align_elements_distributeGraphicalObjectsHorizontally(Layout* layout, std::vector graphicalObjects, const double& spacing); + + void align_elements_distributeEvenGraphicalObjectsHorizontally(Layout* layout, std::vector graphicalObjects, const double& minX, const double& maxX, const double& distance); + + void align_elements_distributeOddGraphicalObjectsHorizontally(Layout* layout, std::vector graphicalObjects, const double& minX, const double& maxX, const double& distance); + + void align_elements_distributeGraphicalObjectsVertically(Layout* layout, std::vector graphicalObjects, const double& spacing); + + void align_elements_distributeEvenGraphicalObjectsVertically(Layout* layout, std::vector graphicalObjects, const double& minY, const double& maxY, const double& distance); + + void align_elements_distributeOddGraphicalObjectsVertically(Layout* layout, std::vector graphicalObjects, const double& minY, const double& maxY, const double& distance); + + const double align_elements_findDistributionDistance(const double& minPosition, const double& maxPosition, const unsigned int& numGraphicalObjects, const double& spacing); + + const double align_elements_getMinPositionX(std::vector graphicalObjects); + + const double align_elements_getMinPositionY(std::vector graphicalObjects); + + const double align_elements_getMaxPositionX(std::vector graphicalObjects); + + const double align_elements_getMaxPositionY(std::vector graphicalObjects); + + const double align_elements_getMinCenterX(std::vector graphicalObjects); + + const double align_elements_getMinCenterY(std::vector graphicalObjects); + + const double align_elements_getMaxCenterX(std::vector graphicalObjects); + + const double align_elements_getMaxCenterY(std::vector graphicalObjects); + +} + +#endif diff --git a/src/autolayout/libsbmlnetwork_autolayout.cpp b/src/features/autolayout/libsbmlnetwork_autolayout.cpp similarity index 58% rename from src/autolayout/libsbmlnetwork_autolayout.cpp rename to src/features/autolayout/libsbmlnetwork_autolayout.cpp index a2fbbb4..b28fc9f 100755 --- a/src/autolayout/libsbmlnetwork_autolayout.cpp +++ b/src/features/autolayout/libsbmlnetwork_autolayout.cpp @@ -1,8 +1,10 @@ #include "libsbmlnetwork_autolayout.h" -#include "../libsbmlnetwork_layout_helpers.h" -#include "../libsbmlnetwork_sbmldocument_helpers.h" -#include "../libsbmlnetwork_common.h" +#include "../../libsbmlnetwork_layout_helpers.h" +#include "../../libsbmlnetwork_common.h" #include "libsbmlnetwork_fruchterman_reingold_algorithm.h" +#include "../error_log/libsbmlnetwork_error_log.h" +#include "../user_data/libsbmlnetwork_user_data.h" +#include "../defaults/libsbmlnetwork_defaults_layout.h" #include #include @@ -10,41 +12,41 @@ namespace LIBSBMLNETWORK_CPP_NAMESPACE { -void locateGlyphs(Model *model, Layout *layout, const bool &useNameAsTextLabel) { - double stiffness = getStiffness(layout); - double gravity = getGravity(layout); +void autolayout_locateGlyphs(Model *model, Layout *layout, const bool &useNameAsTextLabel) { + double stiffness = autolayout_getStiffness(layout); + double gravity = autolayout_getGravity(layout); bool useMagnetism = false; bool useGrid = false; std::srand(time(0)); - randomizeGlyphsLocations(model, layout); + autolayout_randomizeGlyphsLocations(model, layout); FruchtermanReingoldAlgorithmBase *autoLayoutAlgorithm = new FruchtermanReingoldAutoLayoutAlgorithm(); autoLayoutAlgorithm->setElements(model, layout, useNameAsTextLabel); autoLayoutAlgorithm->setStiffness(stiffness); autoLayoutAlgorithm->setGravity(gravity); autoLayoutAlgorithm->setUseMagnetism(useMagnetism); autoLayoutAlgorithm->setUseGrid(useGrid); - autoLayoutAlgorithm->updateNodesLockedStatus(); - autoLayoutAlgorithm->updateConnectionsLockedStatus(); + autoLayoutAlgorithm->updateNodesFixedPositionStatus(); + autoLayoutAlgorithm->updateConnectionsFixedPositionStatus(); autoLayoutAlgorithm->setWidth(layout); autoLayoutAlgorithm->setHeight(layout); autoLayoutAlgorithm->apply(); - updateCompartmentsExtents(model, layout); - updateLayoutDimensions(layout); + autolayout_updateCompartmentsExtents(model, layout); + autolayout_updateLayoutDimensions(layout); delete autoLayoutAlgorithm; - if (!adjustLayoutDimensions(layout)) { - if (autolayoutMayStillConverge(layout)) { - updateGravity(layout); - updateStiffness(layout); - locateGlyphs(model, layout, useNameAsTextLabel); + if (!autolayout_adjustLayoutDimensions(layout)) { + if (autolayout_autolayoutMayStillConverge(layout)) { + autolayout_updateGravity(layout); + autolayout_updateStiffness(layout); + autolayout_locateGlyphs(model, layout, useNameAsTextLabel); } else - addErrorToLog(layout, "Auto-layout fails to converge with the given layout dimensions. Please adjust layout width and height and try again."); + error_log_addErrorToLog(layout, "Auto-layout fails to converge with the given layout dimensions. Please adjust layout width and height and try again."); } } -void locateReactions(Model *model, Layout *layout, const bool &useNameAsTextLabel) { - double stiffness = getStiffness(layout); - double gravity = getGravity(layout); +void autolayout_locateReactions(Model *model, Layout *layout, const bool &useNameAsTextLabel) { + double stiffness = autolayout_getStiffness(layout); + double gravity = autolayout_getGravity(layout); bool useMagnetism = false; bool useGrid = false; FruchtermanReingoldAlgorithmBase* autoLayoutAlgorithm = new FruchtermanReingoldUpdateCurvesAlgorithm(); @@ -53,62 +55,62 @@ void locateReactions(Model *model, Layout *layout, const bool &useNameAsTextLabe autoLayoutAlgorithm->setGravity(gravity); autoLayoutAlgorithm->setUseMagnetism(useMagnetism); autoLayoutAlgorithm->setUseGrid(useGrid); - autoLayoutAlgorithm->updateNodesLockedStatus(); + autoLayoutAlgorithm->updateNodesFixedPositionStatus(); autoLayoutAlgorithm->setWidth(layout); autoLayoutAlgorithm->setHeight(layout); autoLayoutAlgorithm->apply(); - updateCompartmentsExtents(model, layout); - updateLayoutDimensions(layout); + autolayout_updateCompartmentsExtents(model, layout); + autolayout_updateLayoutDimensions(layout); delete autoLayoutAlgorithm; } -const double getStiffness(Layout *layout) { - std::string stiffness = LIBSBMLNETWORK_CPP_NAMESPACE::getUserData(layout, "stiffness"); +const double autolayout_getStiffness(Layout *layout) { + std::string stiffness = LIBSBMLNETWORK_CPP_NAMESPACE::user_data_getUserData(layout, "stiffness"); if (stiffness.empty()) { - setStiffness(layout, 10.0); + autolayout_setStiffness(layout, 10.0); return 10.0; } return std::stod(stiffness); } -void setStiffness(Layout *layout, const double &stiffness) { - LIBSBMLNETWORK_CPP_NAMESPACE::setUserData(layout, "stiffness", std::to_string(stiffness)); +void autolayout_setStiffness(Layout *layout, const double &stiffness) { + LIBSBMLNETWORK_CPP_NAMESPACE::user_data_setUserData(layout, "stiffness", std::to_string(stiffness)); } -void updateStiffness(Layout *layout) { - setStiffness(layout, getStiffnessAdjustmentFactor(layout) * getStiffness(layout)); +void autolayout_updateStiffness(Layout *layout) { + autolayout_setStiffness(layout, autolayout_getStiffnessAdjustmentFactor(layout) * autolayout_getStiffness(layout)); } -double getStiffnessAdjustmentFactor(Layout *layout) { - return std::max(std::min(getDesiredDimensionToCurrentDimensionRatio(layout), 1.1), 0.9); +double autolayout_getStiffnessAdjustmentFactor(Layout *layout) { + return std::max(std::min(autolayout_getDesiredDimensionToCurrentDimensionRatio(layout), 1.1), 0.9); } -const double getGravity(Layout *layout) { - std::string gravity = LIBSBMLNETWORK_CPP_NAMESPACE::getUserData(layout, "gravity"); +const double autolayout_getGravity(Layout *layout) { + std::string gravity = LIBSBMLNETWORK_CPP_NAMESPACE::user_data_getUserData(layout, "gravity"); if (gravity.empty()) { - setGravity(layout, 15.0); + autolayout_setGravity(layout, 15.0); return 15.0; } return std::stod(gravity); } -void setGravity(Layout *layout, const double &gravity) { - LIBSBMLNETWORK_CPP_NAMESPACE::setUserData(layout, "gravity", std::to_string(gravity)); +void autolayout_setGravity(Layout *layout, const double &gravity) { + LIBSBMLNETWORK_CPP_NAMESPACE::user_data_setUserData(layout, "gravity", std::to_string(gravity)); } -void updateGravity(Layout *layout) { - setGravity(layout, getGravityAdjustmentFactor(layout) * getGravity(layout)); +void autolayout_updateGravity(Layout *layout) { + autolayout_setGravity(layout, autolayout_getGravityAdjustmentFactor(layout) * autolayout_getGravity(layout)); } -double getGravityAdjustmentFactor(Layout *layout) { - return std::max(std::min(getCurrentDimensionToDesiredDimensionRatio(layout), 1.05), 0.95); +double autolayout_getGravityAdjustmentFactor(Layout *layout) { + return std::max(std::min(autolayout_getCurrentDimensionToDesiredDimensionRatio(layout), 1.05), 0.95); } -double getCurrentDimensionToDesiredDimensionRatio(Layout *layout) { - double desiredWidth = getLayoutDimensionsDesiredWidth(layout); - double desiredHeight = getLayoutDimensionsDesiredHeight(layout); +double autolayout_getCurrentDimensionToDesiredDimensionRatio(Layout *layout) { + double desiredWidth = autolayout_getLayoutDimensionsDesiredWidth(layout); + double desiredHeight = autolayout_getLayoutDimensionsDesiredHeight(layout); if (layout->getDimensions()->width() < desiredWidth || layout->getDimensions()->height() < desiredHeight) { double widthRatio = layout->getDimensions()->width() / desiredWidth; double heightRatio = layout->getDimensions()->height() / desiredHeight; @@ -123,9 +125,9 @@ double getCurrentDimensionToDesiredDimensionRatio(Layout *layout) { return 1.0; } -double getDesiredDimensionToCurrentDimensionRatio(Layout *layout) { - double desiredWidth = getLayoutDimensionsDesiredWidth(layout); - double desiredHeight = getLayoutDimensionsDesiredHeight(layout); +double autolayout_getDesiredDimensionToCurrentDimensionRatio(Layout *layout) { + double desiredWidth = autolayout_getLayoutDimensionsDesiredWidth(layout); + double desiredHeight = autolayout_getLayoutDimensionsDesiredHeight(layout); if (layout->getDimensions()->width() < desiredWidth || layout->getDimensions()->height() < desiredHeight) { double widthRatio = desiredWidth / layout->getDimensions()->width(); double heightRatio = desiredHeight / layout->getDimensions()->height(); @@ -140,36 +142,34 @@ double getDesiredDimensionToCurrentDimensionRatio(Layout *layout) { return 1.0; } -void randomizeGlyphsLocations(Model *model, Layout *layout) { +void autolayout_randomizeGlyphsLocations(Model *model, Layout *layout) { double canvasWidth = layout->getDimensions()->width(); double canvasHeight = layout->getDimensions()->height(); - randomizeSpeciesGlyphsLocations(model, layout, canvasWidth, canvasHeight); - randomizeReactionGlyphsLocations(model, layout, canvasWidth, canvasHeight); + autolayout_randomizeSpeciesGlyphsLocations(model, layout, canvasWidth, canvasHeight); + autolayout_randomizeReactionGlyphsLocations(model, layout, canvasWidth, canvasHeight); } -void -randomizeSpeciesGlyphsLocations(Model *model, Layout *layout, const double &canvasWidth, const double &canvasHeight) { +void autolayout_randomizeSpeciesGlyphsLocations(Model *model, Layout *layout, const double &canvasWidth, const double &canvasHeight) { for (int i = 0; i < layout->getNumSpeciesGlyphs(); i++) - randomizeBoundingBoxesPosition(layout->getSpeciesGlyph(i)->getBoundingBox(), canvasWidth, canvasHeight); + autolayout_randomizeBoundingBoxesPosition(layout->getSpeciesGlyph(i)->getBoundingBox(), canvasWidth, canvasHeight); } -void randomizeReactionGlyphsLocations(Model *model, Layout *layout, const double &canvasWidth, const double &canvasHeight) { +void autolayout_randomizeReactionGlyphsLocations(Model *model, Layout *layout, const double &canvasWidth, const double &canvasHeight) { for (int i = 0; i < layout->getNumReactionGlyphs(); i++) { if (layout->getReactionGlyph(i)->isSetCurve()) - randomizeCurveCenterPoint(layout->getReactionGlyph(i)->getCurve(), canvasWidth, canvasHeight); + autolayout_randomizeCurveCenterPoint(layout->getReactionGlyph(i)->getCurve(), canvasWidth, canvasHeight); else - randomizeBoundingBoxesPosition(layout->getReactionGlyph(i)->getBoundingBox(), canvasWidth, canvasHeight); + autolayout_randomizeBoundingBoxesPosition(layout->getReactionGlyph(i)->getBoundingBox(), canvasWidth, canvasHeight); } } -void -randomizeBoundingBoxesPosition(BoundingBox *boundingBox, const double &canvasWidth, const double &canvasHeight) { +void autolayout_randomizeBoundingBoxesPosition(BoundingBox *boundingBox, const double &canvasWidth, const double &canvasHeight) { double offset = 30.0; boundingBox->setX(offset + (std::rand() % int(canvasWidth - offset))); boundingBox->setY(offset + (std::rand() % int(canvasHeight - offset))); } -void randomizeCurveCenterPoint(Curve *curve, const double &canvasWidth, const double &canvasHeight) { +void autolayout_randomizeCurveCenterPoint(Curve *curve, const double &canvasWidth, const double &canvasHeight) { double offset = 30.0; double randomPointX = offset + (std::rand() % int(canvasWidth - offset)); double randomPointY = offset + (std::rand() % int(canvasHeight - offset)); @@ -184,21 +184,20 @@ void randomizeCurveCenterPoint(Curve *curve, const double &canvasWidth, const do cubicBezier->getBasePoint2()->setY(randomPointY); } -void -initializeCompartmentGlyphExtents(BoundingBox *compartmentGlyphBoundingBox, BoundingBox *speciesGlyphBoundingBox) { - const double padding = getDefaultAutoLayoutPadding(); +void autolayout_initializeCompartmentGlyphExtents(BoundingBox *compartmentGlyphBoundingBox, BoundingBox *speciesGlyphBoundingBox) { + const double padding = defaults_getDefaultAutoLayoutPadding(); compartmentGlyphBoundingBox->setX(speciesGlyphBoundingBox->x() - padding); compartmentGlyphBoundingBox->setY(speciesGlyphBoundingBox->y() - padding); compartmentGlyphBoundingBox->setWidth(speciesGlyphBoundingBox->width() + 2 * padding); compartmentGlyphBoundingBox->setHeight(speciesGlyphBoundingBox->height() + 2 * padding); } -void updateCompartmentsExtents(Model *model, Layout *layout) { - updateCompartmentsExtentsUsingTheirElementsExtents(model, layout); - updateCompartmentsExtentsUsingTheirPresetAttributes(layout); +void autolayout_updateCompartmentsExtents(Model *model, Layout *layout) { + autolayout_updateCompartmentsExtentsUsingTheirElementsExtents(model, layout); + autolayout_updateCompartmentsExtentsUsingTheirPresetAttributes(layout); } -void updateCompartmentsExtentsUsingTheirElementsExtents(Model *model, Layout *layout) { +void autolayout_updateCompartmentsExtentsUsingTheirElementsExtents(Model *model, Layout *layout) { std::vector extentsInitializedCompartmentGlyphIds; for (int i = 0; i < layout->getNumSpeciesGlyphs(); i++) { Compartment *compartment = findSpeciesGlyphCompartment(model, layout->getSpeciesGlyph(i)); @@ -210,11 +209,11 @@ void updateCompartmentsExtentsUsingTheirElementsExtents(Model *model, Layout *la if (std::find(extentsInitializedCompartmentGlyphIds.begin(), extentsInitializedCompartmentGlyphIds.end(), compartmentGlyph->getId()) == extentsInitializedCompartmentGlyphIds.end()) { - initializeCompartmentGlyphExtents(compartmentGlyph->getBoundingBox(), + autolayout_initializeCompartmentGlyphExtents(compartmentGlyph->getBoundingBox(), layout->getSpeciesGlyph(i)->getBoundingBox()); extentsInitializedCompartmentGlyphIds.push_back(compartmentGlyph->getId()); } - updateCompartmentExtentsUsingItsElementsExtents(compartmentGlyph->getBoundingBox(), + autolayout_updateCompartmentExtentsUsingItsElementsExtents(compartmentGlyph->getBoundingBox(), layout->getSpeciesGlyph(i)->getBoundingBox()); } } @@ -224,17 +223,17 @@ void updateCompartmentsExtentsUsingTheirElementsExtents(Model *model, Layout *la layout->getReactionGlyph(i)); if (compartmentGlyph) { if (layout->getReactionGlyph(i)->isSetCurve()) - updateCompartmentExtentsUsingItsElementsExtents(compartmentGlyph->getBoundingBox(), + autolayout_updateCompartmentExtentsUsingItsElementsExtents(compartmentGlyph->getBoundingBox(), layout->getReactionGlyph(i)->getCurve()); else - updateCompartmentExtentsUsingItsElementsExtents(compartmentGlyph->getBoundingBox(), + autolayout_updateCompartmentExtentsUsingItsElementsExtents(compartmentGlyph->getBoundingBox(), layout->getReactionGlyph(i)->getBoundingBox()); } } } -void updateCompartmentExtentsUsingItsElementsExtents(BoundingBox *compartmentGlyphBoundingBox, BoundingBox *speciesGlyphBoundingBox) { - const double padding = getDefaultAutoLayoutPadding(); +void autolayout_updateCompartmentExtentsUsingItsElementsExtents(BoundingBox *compartmentGlyphBoundingBox, BoundingBox *speciesGlyphBoundingBox) { + const double padding = defaults_getDefaultAutoLayoutPadding(); if (speciesGlyphBoundingBox->x() - padding < compartmentGlyphBoundingBox->x()) { compartmentGlyphBoundingBox->setWidth(compartmentGlyphBoundingBox->width() + (compartmentGlyphBoundingBox->x() - @@ -266,8 +265,8 @@ void updateCompartmentExtentsUsingItsElementsExtents(BoundingBox *compartmentGly } } -void updateCompartmentExtentsUsingItsElementsExtents(BoundingBox *compartmentGlyphBoundingBox, Curve *reactionCurve) { - const double padding = getDefaultAutoLayoutPadding(); +void autolayout_updateCompartmentExtentsUsingItsElementsExtents(BoundingBox *compartmentGlyphBoundingBox, Curve *reactionCurve) { + const double padding = defaults_getDefaultAutoLayoutPadding(); double reactionCenterX = 0.5 * (reactionCurve->getCurveSegment(0)->getStart()->x() + reactionCurve->getCurveSegment(0)->getEnd()->x()); double reactionCenterY = 0.5 * (reactionCurve->getCurveSegment(0)->getStart()->y() + @@ -294,32 +293,31 @@ void updateCompartmentExtentsUsingItsElementsExtents(BoundingBox *compartmentGly } } -void updateCompartmentsExtentsUsingTheirPresetAttributes(Layout *layout) { +void autolayout_updateCompartmentsExtentsUsingTheirPresetAttributes(Layout *layout) { for (int i = 0; i < layout->getNumCompartmentGlyphs(); i++) { CompartmentGlyph *compartmentGlyph = layout->getCompartmentGlyph(i); - if (LIBSBMLNETWORK_CPP_NAMESPACE::getUserData(compartmentGlyph, "locked") == "true") { - std::string x = LIBSBMLNETWORK_CPP_NAMESPACE::getUserData(compartmentGlyph, "x"); + if (LIBSBMLNETWORK_CPP_NAMESPACE::user_data_getUserData(compartmentGlyph, "fixed_position") == "true") { + std::string x = LIBSBMLNETWORK_CPP_NAMESPACE::user_data_getUserData(compartmentGlyph, "x"); if (!x.empty()) compartmentGlyph->getBoundingBox()->setX(std::stod(x)); - std::string y = LIBSBMLNETWORK_CPP_NAMESPACE::getUserData(compartmentGlyph, "y"); + std::string y = LIBSBMLNETWORK_CPP_NAMESPACE::user_data_getUserData(compartmentGlyph, "y"); if (!y.empty()) compartmentGlyph->getBoundingBox()->setY(std::stod(y)); } - if (LIBSBMLNETWORK_CPP_NAMESPACE::getUserData(compartmentGlyph, "fixed_width") == "true") { - std::string width = LIBSBMLNETWORK_CPP_NAMESPACE::getUserData(compartmentGlyph, "width"); + if (LIBSBMLNETWORK_CPP_NAMESPACE::user_data_getUserData(compartmentGlyph, "fixed_width") == "true") { + std::string width = LIBSBMLNETWORK_CPP_NAMESPACE::user_data_getUserData(compartmentGlyph, "width"); if (!width.empty()) compartmentGlyph->getBoundingBox()->setWidth(std::stod(width)); } - if (LIBSBMLNETWORK_CPP_NAMESPACE::getUserData(compartmentGlyph, "fixed_height") == "true") { - std::string height = LIBSBMLNETWORK_CPP_NAMESPACE::getUserData(compartmentGlyph, "height"); + if (LIBSBMLNETWORK_CPP_NAMESPACE::user_data_getUserData(compartmentGlyph, "fixed_height") == "true") { + std::string height = LIBSBMLNETWORK_CPP_NAMESPACE::user_data_getUserData(compartmentGlyph, "height"); if (!height.empty()) compartmentGlyph->getBoundingBox()->setHeight(std::stod(height)); } } } -void updateLayoutDimensions(Layout *layout) { - const double padding = getDefaultAutoLayoutPadding(); +void autolayout_updateLayoutDimensions(Layout *layout) { if (!layoutContainsGlyphs(layout)) { layout->getDimensions()->setWidth(0); layout->getDimensions()->setHeight(0); @@ -327,84 +325,84 @@ void updateLayoutDimensions(Layout *layout) { } else { double maxX; double maxY; - extractExtents(layout, maxX, maxY); + autolayout_extractExtents(layout, maxX, maxY); layout->getDimensions()->setWidth(maxX); layout->getDimensions()->setHeight(maxY); } } -const bool adjustLayoutDimensions(Layout *layout) { - double desiredWidth = getLayoutDimensionsDesiredWidth(layout); +const bool autolayout_adjustLayoutDimensions(Layout *layout) { + double desiredWidth = autolayout_getLayoutDimensionsDesiredWidth(layout); double widthGap = desiredWidth - layout->getDimensions()->width(); - double desiredHeight = getLayoutDimensionsDesiredHeight(layout); + double desiredHeight = autolayout_getLayoutDimensionsDesiredHeight(layout); double heightGap = desiredHeight - layout->getDimensions()->height(); if (widthGap <= 0.1 * desiredWidth && heightGap <= 0.1 * desiredHeight) { - setLayoutDimensionsDesiredWidth(layout, layout->getDimensions()->width()); - setLayoutDimensionsDesiredHeight(layout, layout->getDimensions()->height()); + autolayout_setLayoutDimensionsDesiredWidth(layout, layout->getDimensions()->width()); + autolayout_setLayoutDimensionsDesiredHeight(layout, layout->getDimensions()->height()); return true; } return false; } -const double getLayoutDimensionsDesiredWidth(Layout *layout) {; - std::string presetWidth = LIBSBMLNETWORK_CPP_NAMESPACE::getUserData(layout->getDimensions(), "width"); +const double autolayout_getLayoutDimensionsDesiredWidth(Layout *layout) {; + std::string presetWidth = LIBSBMLNETWORK_CPP_NAMESPACE::user_data_getUserData(layout->getDimensions(), "width"); if (!presetWidth.empty()) return std::stod(presetWidth); return layout->getDimensions()->width(); } -void setLayoutDimensionsDesiredWidth(Layout *layout, const double &width) { - if (!LIBSBMLNETWORK_CPP_NAMESPACE::getUserData(layout->getDimensions(), "width").empty()) - LIBSBMLNETWORK_CPP_NAMESPACE::setUserData(layout->getDimensions(), "width", std::to_string(width)); +void autolayout_setLayoutDimensionsDesiredWidth(Layout *layout, const double &width) { + if (!LIBSBMLNETWORK_CPP_NAMESPACE::user_data_getUserData(layout->getDimensions(), "width").empty()) + LIBSBMLNETWORK_CPP_NAMESPACE::user_data_setUserData(layout->getDimensions(), "width", std::to_string(width)); } -const double getLayoutDimensionsDesiredHeight(Layout *layout) { - std::string presetHeight = LIBSBMLNETWORK_CPP_NAMESPACE::getUserData(layout->getDimensions(), "height"); +const double autolayout_getLayoutDimensionsDesiredHeight(Layout *layout) { + std::string presetHeight = LIBSBMLNETWORK_CPP_NAMESPACE::user_data_getUserData(layout->getDimensions(), "height"); if (!presetHeight.empty()) return std::stod(presetHeight); return layout->getDimensions()->height(); } -void setLayoutDimensionsDesiredHeight(Layout *layout, const double &height) { - if (!LIBSBMLNETWORK_CPP_NAMESPACE::getUserData(layout->getDimensions(), "height").empty()) - LIBSBMLNETWORK_CPP_NAMESPACE::setUserData(layout->getDimensions(), "height", std::to_string(height)); +void autolayout_setLayoutDimensionsDesiredHeight(Layout *layout, const double &height) { + if (!LIBSBMLNETWORK_CPP_NAMESPACE::user_data_getUserData(layout->getDimensions(), "height").empty()) + LIBSBMLNETWORK_CPP_NAMESPACE::user_data_setUserData(layout->getDimensions(), "height", std::to_string(height)); } -const bool autolayoutMayStillConverge(Layout *layout) { - if (getGravity(layout) > 1.0) +const bool autolayout_autolayoutMayStillConverge(Layout *layout) { + if (autolayout_getGravity(layout) > 1.0) return true; return false; } -void extractExtents(Layout *layout, double &maxX, double &maxY) { +void autolayout_extractExtents(Layout *layout, double &maxX, double &maxY) { double minX = INT_MAX; double minY = INT_MAX; maxX = INT_MIN; maxY = INT_MIN; for (int i = 0; i < layout->getNumCompartmentGlyphs(); i++) - extractExtents(layout->getCompartmentGlyph(i)->getBoundingBox(), minX, minY, maxX, maxY); + autolayout_extractExtents(layout->getCompartmentGlyph(i)->getBoundingBox(), minX, minY, maxX, maxY); for (int i = 0; i < layout->getNumSpeciesGlyphs(); i++) - extractExtents(layout->getSpeciesGlyph(i)->getBoundingBox(), minX, minY, maxX, maxY); + autolayout_extractExtents(layout->getSpeciesGlyph(i)->getBoundingBox(), minX, minY, maxX, maxY); for (int i = 0; i < layout->getNumReactionGlyphs(); i++) { if (layout->getReactionGlyph(i)->isSetCurve()) - extractExtents(layout->getReactionGlyph(i)->getCurve(), minX, minY, maxX, maxY); + autolayout_extractExtents(layout->getReactionGlyph(i)->getCurve(), minX, minY, maxX, maxY); else - extractExtents(layout->getReactionGlyph(i)->getBoundingBox(), minX, minY, maxX, maxY); + autolayout_extractExtents(layout->getReactionGlyph(i)->getBoundingBox(), minX, minY, maxX, maxY); } } -void extractExtents(BoundingBox *boundingBox, double &minX, double &minY, double &maxX, double &maxY) { +void autolayout_extractExtents(BoundingBox *boundingBox, double &minX, double &minY, double &maxX, double &maxY) { minX = std::min(minX, boundingBox->x()); minY = std::min(minY, boundingBox->y()); maxX = std::max(maxX, boundingBox->x() + boundingBox->width()); maxY = std::max(maxY, boundingBox->y() + boundingBox->height()); } -void extractExtents(Curve *reactionCurve, double &minX, double &minY, double &maxX, double &maxY) { +void autolayout_extractExtents(Curve *reactionCurve, double &minX, double &minY, double &maxX, double &maxY) { double reactionCenterX = 0.5 * (reactionCurve->getCurveSegment(0)->getStart()->x() + reactionCurve->getCurveSegment(0)->getEnd()->x()); double reactionCenterY = 0.5 * (reactionCurve->getCurveSegment(0)->getStart()->y() + diff --git a/src/features/autolayout/libsbmlnetwork_autolayout.h b/src/features/autolayout/libsbmlnetwork_autolayout.h new file mode 100755 index 0000000..100096a --- /dev/null +++ b/src/features/autolayout/libsbmlnetwork_autolayout.h @@ -0,0 +1,86 @@ +#ifndef __LIBSBMLNETWORK_AUTOLAYOUT_H_ +#define __LIBSBMLNETWORK_AUTOLAYOUT_H_ + +#ifndef SWIG +#include "sbml/SBMLTypes.h" +#include "sbml/packages/layout/common/LayoutExtensionTypes.h" +#endif + +using namespace libsbml; + +namespace LIBSBMLNETWORK_CPP_NAMESPACE { + +void autolayout_locateGlyphs(Model* model, Layout* layout, const bool& useNameAsTextLabel = true); + +void autolayout_locateReactions(Model *model, Layout *layout, const bool& useNameAsTextLabel = false); + +const double autolayout_getStiffness(Layout *layout); + +void autolayout_setStiffness(Layout *layout, const double& stiffness); + +void autolayout_updateStiffness(Layout *layout); + +double autolayout_getStiffnessAdjustmentFactor(Layout *layout); + +const double autolayout_getGravity(Layout *layout); + +void autolayout_setGravity(Layout *layout, const double& gravity); + +void autolayout_updateGravity(Layout *layout); + +double autolayout_getGravityAdjustmentFactor(Layout *layout); + +double autolayout_getCurrentDimensionToDesiredDimensionRatio(Layout *layout); + +double autolayout_getDesiredDimensionToCurrentDimensionRatio(Layout *layout); + +void autolayout_randomizeGlyphsLocations(Model* model, Layout* layout); + +void autolayout_randomizeSpeciesGlyphsLocations(Model* model, Layout* layout, const double& canvasWidth, const double& canvasHeight); + +void autolayout_randomizeReactionGlyphsLocations(Model* model, Layout* layout, const double& canvasWidth, const double& canvasHeight); + +void autolayout_randomizeBoundingBoxesPosition(BoundingBox* boundingBox, const double& canvasWidth, const double& canvasHeight); + +void autolayout_randomizeCurveCenterPoint(Curve* curve, const double& canvasWidth, const double& canvasHeight); + +void autolayout_setGlyphsDimensions(Model *model, Layout *layout); + +void autolayout_setSpeciesGlyphDimensions(Model *model, SpeciesGlyph* speciesGlyph); + +void autolayout_initializeCompartmentGlyphExtents(BoundingBox* compartmentGlyphBoundingBox, BoundingBox* speciesGlyphBoundingBox); + +void autolayout_updateCompartmentsExtents(Model *model, Layout *layout); + +void autolayout_updateCompartmentsExtentsUsingTheirElementsExtents(Model *model, Layout *layout); + +void autolayout_updateCompartmentExtentsUsingItsElementsExtents(BoundingBox* compartmentGlyphBoundingBox, BoundingBox* speciesGlyphBoundingBox); + +void autolayout_updateCompartmentExtentsUsingItsElementsExtents(BoundingBox* compartmentGlyphBoundingBox, Curve* reactionCurve); + +void autolayout_updateCompartmentsExtentsUsingTheirPresetAttributes(Layout *layout); + +void autolayout_updateLayoutDimensions(Layout* layout); + +const bool autolayout_adjustLayoutDimensions(Layout *layout); + +const double autolayout_getLayoutDimensionsDesiredWidth(Layout *layout); + +void autolayout_setLayoutDimensionsDesiredWidth(Layout *layout, const double& width); + +const double autolayout_getLayoutDimensionsDesiredHeight(Layout *layout); + +void autolayout_setLayoutDimensionsDesiredHeight(Layout *layout, const double& height); + +const bool autolayout_autolayoutMayStillConverge(Layout *layout); + +void autolayout_extractExtents(Layout* layout, double &maxX, double &maxY); + +void autolayout_extractExtents(BoundingBox* boundingBox, double &minX, double &minY, double &maxX, double &maxY); + +void autolayout_extractExtents(Curve* reactionCurve, double &minX, double &minY, double &maxX, double &maxY); + +} + +#endif + diff --git a/src/autolayout/libsbmlnetwork_autolayout_connection.cpp b/src/features/autolayout/libsbmlnetwork_autolayout_connection.cpp similarity index 96% rename from src/autolayout/libsbmlnetwork_autolayout_connection.cpp rename to src/features/autolayout/libsbmlnetwork_autolayout_connection.cpp index 9eb28ba..549dd12 100644 --- a/src/autolayout/libsbmlnetwork_autolayout_connection.cpp +++ b/src/features/autolayout/libsbmlnetwork_autolayout_connection.cpp @@ -17,9 +17,9 @@ const std::string AutoLayoutConnection::getId() { return _reactionGlyph->getId(); } -void AutoLayoutConnection::updateLockedStatus() {; +void AutoLayoutConnection::updateFixedPositionStatus() {; for (int i = 0; i < _curves.size(); i++) - ((AutoLayoutCurve*)_curves.at(i))->updateLockedStatus(); + ((AutoLayoutCurve*)_curves.at(i))->updateFixedPositionStatus(); } void AutoLayoutConnection::setCentroidNode(const bool& useNameAsTextLabel) { diff --git a/src/autolayout/libsbmlnetwork_autolayout_connection.h b/src/features/autolayout/libsbmlnetwork_autolayout_connection.h similarity index 95% rename from src/autolayout/libsbmlnetwork_autolayout_connection.h rename to src/features/autolayout/libsbmlnetwork_autolayout_connection.h index 5cc70b3..eb8fe48 100644 --- a/src/autolayout/libsbmlnetwork_autolayout_connection.h +++ b/src/features/autolayout/libsbmlnetwork_autolayout_connection.h @@ -12,7 +12,7 @@ class AutoLayoutConnection : public AutoLayoutObjectBase { const std::string getId() override; - void updateLockedStatus(); + void updateFixedPositionStatus(); void setCentroidNode(const bool& useNameAsTextLabel); diff --git a/src/autolayout/libsbmlnetwork_autolayout_curve.cpp b/src/features/autolayout/libsbmlnetwork_autolayout_curve.cpp similarity index 81% rename from src/autolayout/libsbmlnetwork_autolayout_curve.cpp rename to src/features/autolayout/libsbmlnetwork_autolayout_curve.cpp index 4c73e9b..77157ac 100644 --- a/src/autolayout/libsbmlnetwork_autolayout_curve.cpp +++ b/src/features/autolayout/libsbmlnetwork_autolayout_curve.cpp @@ -1,11 +1,11 @@ #include "libsbmlnetwork_autolayout_curve.h" #include "libsbmlnetwork_autolayout_node.h" -#include "../libsbmlnetwork_layout_helpers.h" -#include "../libsbmlnetwork_sbmldocument_helpers.h" +#include "../../libsbmlnetwork_layout_helpers.h" +#include "../user_data/libsbmlnetwork_user_data.h" AutoLayoutCurve::AutoLayoutCurve(Model* model, Layout* layout, SpeciesReferenceGlyph* speciesReferenceGlyph) : AutoLayoutObjectBase(model, layout) { _speciesReferenceGlyph = speciesReferenceGlyph; - setLocked(false); + setPositionFixed(false); } const std::string AutoLayoutCurve::getId() { @@ -24,28 +24,28 @@ const std::string AutoLayoutCurve::getRoleString() { return _speciesReferenceGlyph->getRoleString(); } -const bool AutoLayoutCurve::isLocked() { - return _locked; +const bool AutoLayoutCurve::isPositionFixed() { + return _positionFixed; } -void AutoLayoutCurve::setLocked(const bool& locked) { - _locked = locked; +void AutoLayoutCurve::setPositionFixed(const bool& value) { + _positionFixed = value; } -void AutoLayoutCurve::updateLockedStatus() {; - if (LIBSBMLNETWORK_CPP_NAMESPACE::getUserData(_speciesReferenceGlyph, "locked") == "true") { - setLocked(true); +void AutoLayoutCurve::updateFixedPositionStatus() {; + if (LIBSBMLNETWORK_CPP_NAMESPACE::user_data_getUserData(_speciesReferenceGlyph, "fixed_position") == "true") { + setPositionFixed(true); int curveSegmentIndex = 0; LineSegment* lineSegment = _speciesReferenceGlyph->getCurve()->getCurveSegment(curveSegmentIndex); - lineSegment->getStart()->setX(std::stod(LIBSBMLNETWORK_CPP_NAMESPACE::getUserData(_speciesReferenceGlyph, std::to_string(curveSegmentIndex) + ":start_x"))); - lineSegment->getStart()->setY(std::stod(LIBSBMLNETWORK_CPP_NAMESPACE::getUserData(_speciesReferenceGlyph, std::to_string(curveSegmentIndex) + ":start_y"))); - lineSegment->getEnd()->setX(std::stod(LIBSBMLNETWORK_CPP_NAMESPACE::getUserData(_speciesReferenceGlyph, std::to_string(curveSegmentIndex) + ":end_x"))); - lineSegment->getEnd()->setY(std::stod(LIBSBMLNETWORK_CPP_NAMESPACE::getUserData(_speciesReferenceGlyph, std::to_string(curveSegmentIndex) + ":end_y"))); + lineSegment->getStart()->setX(std::stod(LIBSBMLNETWORK_CPP_NAMESPACE::user_data_getUserData(_speciesReferenceGlyph, std::to_string(curveSegmentIndex) + ":start_x"))); + lineSegment->getStart()->setY(std::stod(LIBSBMLNETWORK_CPP_NAMESPACE::user_data_getUserData(_speciesReferenceGlyph, std::to_string(curveSegmentIndex) + ":start_y"))); + lineSegment->getEnd()->setX(std::stod(LIBSBMLNETWORK_CPP_NAMESPACE::user_data_getUserData(_speciesReferenceGlyph, std::to_string(curveSegmentIndex) + ":end_x"))); + lineSegment->getEnd()->setY(std::stod(LIBSBMLNETWORK_CPP_NAMESPACE::user_data_getUserData(_speciesReferenceGlyph, std::to_string(curveSegmentIndex) + ":end_y"))); if (dynamic_cast(lineSegment) != NULL) { - ((CubicBezier*)lineSegment)->getBasePoint1()->setX(std::stod(LIBSBMLNETWORK_CPP_NAMESPACE::getUserData(_speciesReferenceGlyph, std::to_string(curveSegmentIndex) + ":b1_x"))); - ((CubicBezier*)lineSegment)->getBasePoint1()->setY(std::stod(LIBSBMLNETWORK_CPP_NAMESPACE::getUserData(_speciesReferenceGlyph, std::to_string(curveSegmentIndex) + ":b1_y"))); - ((CubicBezier*)lineSegment)->getBasePoint2()->setX(std::stod(LIBSBMLNETWORK_CPP_NAMESPACE::getUserData(_speciesReferenceGlyph, std::to_string(curveSegmentIndex) + ":b2_x"))); - ((CubicBezier*)lineSegment)->getBasePoint2()->setY(std::stod(LIBSBMLNETWORK_CPP_NAMESPACE::getUserData(_speciesReferenceGlyph, std::to_string(curveSegmentIndex) + ":b2_y"))); + ((CubicBezier*)lineSegment)->getBasePoint1()->setX(std::stod(LIBSBMLNETWORK_CPP_NAMESPACE::user_data_getUserData(_speciesReferenceGlyph, std::to_string(curveSegmentIndex) + ":b1_x"))); + ((CubicBezier*)lineSegment)->getBasePoint1()->setY(std::stod(LIBSBMLNETWORK_CPP_NAMESPACE::user_data_getUserData(_speciesReferenceGlyph, std::to_string(curveSegmentIndex) + ":b1_y"))); + ((CubicBezier*)lineSegment)->getBasePoint2()->setX(std::stod(LIBSBMLNETWORK_CPP_NAMESPACE::user_data_getUserData(_speciesReferenceGlyph, std::to_string(curveSegmentIndex) + ":b2_x"))); + ((CubicBezier*)lineSegment)->getBasePoint2()->setY(std::stod(LIBSBMLNETWORK_CPP_NAMESPACE::user_data_getUserData(_speciesReferenceGlyph, std::to_string(curveSegmentIndex) + ":b2_y"))); } } } diff --git a/src/autolayout/libsbmlnetwork_autolayout_curve.h b/src/features/autolayout/libsbmlnetwork_autolayout_curve.h similarity index 87% rename from src/autolayout/libsbmlnetwork_autolayout_curve.h rename to src/features/autolayout/libsbmlnetwork_autolayout_curve.h index 30c97e5..f725b6c 100644 --- a/src/autolayout/libsbmlnetwork_autolayout_curve.h +++ b/src/features/autolayout/libsbmlnetwork_autolayout_curve.h @@ -17,11 +17,11 @@ class AutoLayoutCurve : public AutoLayoutObjectBase { const std::string getRoleString(); - const bool isLocked(); + const bool isPositionFixed(); - void setLocked(const bool& locked); + void setPositionFixed(const bool& positionFixed); - void updateLockedStatus(); + void updateFixedPositionStatus(); const AutoLayoutPoint getNodeSidePoint(); @@ -42,7 +42,7 @@ class AutoLayoutCurve : public AutoLayoutObjectBase { protected: SpeciesReferenceGlyph* _speciesReferenceGlyph; - bool _locked; + bool _positionFixed; }; #endif \ No newline at end of file diff --git a/src/autolayout/libsbmlnetwork_autolayout_node.cpp b/src/features/autolayout/libsbmlnetwork_autolayout_node.cpp similarity index 82% rename from src/autolayout/libsbmlnetwork_autolayout_node.cpp rename to src/features/autolayout/libsbmlnetwork_autolayout_node.cpp index 0dc688a..4274af7 100644 --- a/src/autolayout/libsbmlnetwork_autolayout_node.cpp +++ b/src/features/autolayout/libsbmlnetwork_autolayout_node.cpp @@ -1,15 +1,16 @@ #include "libsbmlnetwork_autolayout_node.h" -#include "../libsbmlnetwork_layout_helpers.h" -#include "../libsbmlnetwork_sbmldocument_helpers.h" -#include "../libsbmlnetwork_common.h" +#include "../../libsbmlnetwork_layout_helpers.h" +#include "../../libsbmlnetwork_common.h" +#include "../user_data/libsbmlnetwork_user_data.h" +#include "../defaults/libsbmlnetwork_defaults_layout.h" // AutoLayoutNodeBase -AutoLayoutNodeBase::AutoLayoutNodeBase(Model* model, Layout* layout, GraphicalObject* graphicalObject, const bool& useNameAsTextLabel, const bool& locked) : AutoLayoutObjectBase(model, layout) { +AutoLayoutNodeBase::AutoLayoutNodeBase(Model* model, Layout* layout, GraphicalObject* graphicalObject, const bool& useNameAsTextLabel, const bool& positionFixed) : AutoLayoutObjectBase(model, layout) { _degree = 0; _useNameAsTextLabel = useNameAsTextLabel; _graphicalObject = graphicalObject; - setLocked(locked); + setPositionFixed(positionFixed); } void AutoLayoutNodeBase::setPosition(const AutoLayoutPoint position) { @@ -54,25 +55,25 @@ void AutoLayoutNodeBase::incrementDegree() { _degree++; } -const bool AutoLayoutNodeBase::isLocked() { - return _locked; +const bool AutoLayoutNodeBase::isPositionFixed() { + return _positionFixed; } -void AutoLayoutNodeBase::setLocked(const bool& locked) { - _locked = locked; +void AutoLayoutNodeBase::setPositionFixed(const bool& positionFixed) { + _positionFixed = positionFixed; } -void AutoLayoutNodeBase::updateLockedStatus() {; - if (LIBSBMLNETWORK_CPP_NAMESPACE::getUserData(_graphicalObject, "locked") == "true") { - setLocked(true); - setX(std::stod(LIBSBMLNETWORK_CPP_NAMESPACE::getUserData(_graphicalObject, "x"))); - setY(std::stod(LIBSBMLNETWORK_CPP_NAMESPACE::getUserData(_graphicalObject, "y"))); +void AutoLayoutNodeBase::updateFixedPositionStatus() {; + if (LIBSBMLNETWORK_CPP_NAMESPACE::user_data_getUserData(_graphicalObject, "fixed_position") == "true") { + setPositionFixed(true); + setX(std::stod(LIBSBMLNETWORK_CPP_NAMESPACE::user_data_getUserData(_graphicalObject, "x"))); + setY(std::stod(LIBSBMLNETWORK_CPP_NAMESPACE::user_data_getUserData(_graphicalObject, "y"))); } } // AutoLayoutNode -AutoLayoutNode::AutoLayoutNode(Model* model, Layout* layout, GraphicalObject* graphicalObject, const bool& useNameAsTextLabel, const bool& locked) : AutoLayoutNodeBase(model, layout, graphicalObject, useNameAsTextLabel, locked) { +AutoLayoutNode::AutoLayoutNode(Model* model, Layout* layout, GraphicalObject* graphicalObject, const bool& useNameAsTextLabel, const bool& positionFixed) : AutoLayoutNodeBase(model, layout, graphicalObject, useNameAsTextLabel, positionFixed) { } @@ -85,12 +86,12 @@ GraphicalObject* AutoLayoutNode::getGraphicalObject() { } void AutoLayoutNode::updateDimensions() { - std::string fixedWidth = LIBSBMLNETWORK_CPP_NAMESPACE::getUserData(getGraphicalObject(), "width"); + std::string fixedWidth = LIBSBMLNETWORK_CPP_NAMESPACE::user_data_getUserData(getGraphicalObject(), "width"); if (fixedWidth.empty()) setWidth(std::max(calculateWidth(), std::max(getWidth(), getDefaultWidth()))); else setWidth(std::stod(fixedWidth)); - std::string fixedHeight = LIBSBMLNETWORK_CPP_NAMESPACE::getUserData(getGraphicalObject(), "height"); + std::string fixedHeight = LIBSBMLNETWORK_CPP_NAMESPACE::user_data_getUserData(getGraphicalObject(), "height"); if (fixedHeight.empty()) setHeight(std::max(calculateHeight(), std::max(getHeight(), getDefaultHeight()))); else @@ -118,7 +119,7 @@ const double AutoLayoutNode::getWidth() { } const double AutoLayoutNode::getDefaultWidth() { - return LIBSBMLNETWORK_CPP_NAMESPACE::getSpeciesDefaultWidth(); + return LIBSBMLNETWORK_CPP_NAMESPACE::defaults_getSpeciesDefaultWidth(); } void AutoLayoutNode::setWidth(const double& width) { @@ -130,7 +131,7 @@ const double AutoLayoutNode::getHeight() { } const double AutoLayoutNode::getDefaultHeight() { - return LIBSBMLNETWORK_CPP_NAMESPACE::getSpeciesDefaultHeight(); + return LIBSBMLNETWORK_CPP_NAMESPACE::defaults_getSpeciesDefaultHeight(); } void AutoLayoutNode::setHeight(const double& height) { @@ -154,7 +155,7 @@ const double AutoLayoutNode::calculateHeight() { // AutoLayoutCentroidNode -AutoLayoutCentroidNode::AutoLayoutCentroidNode(Model* model, Layout* layout, GraphicalObject* graphicalObject, const bool& useNameAsTextLabel, const bool& locked) : AutoLayoutNodeBase(model, layout, graphicalObject, useNameAsTextLabel, locked) { +AutoLayoutCentroidNode::AutoLayoutCentroidNode(Model* model, Layout* layout, GraphicalObject* graphicalObject, const bool& useNameAsTextLabel, const bool& positionFixed) : AutoLayoutNodeBase(model, layout, graphicalObject, useNameAsTextLabel, positionFixed) { } @@ -167,14 +168,14 @@ GraphicalObject* AutoLayoutCentroidNode::getGraphicalObject() { } void AutoLayoutCentroidNode::updateDimensions() { - std::string fixedWidth = LIBSBMLNETWORK_CPP_NAMESPACE::getUserData(getGraphicalObject(), "width"); + std::string fixedWidth = LIBSBMLNETWORK_CPP_NAMESPACE::user_data_getUserData(getGraphicalObject(), "width"); if (fixedWidth.empty()) { if (!isSetCurve()) setWidth(std::max(calculateWidth(), getWidth())); } else setWidth(std::stod(fixedWidth)); - std::string fixedHeight = LIBSBMLNETWORK_CPP_NAMESPACE::getUserData(getGraphicalObject(), "height"); + std::string fixedHeight = LIBSBMLNETWORK_CPP_NAMESPACE::user_data_getUserData(getGraphicalObject(), "height"); if (fixedHeight.empty()) { if (!isSetCurve()) setHeight(std::max(calculateHeight(), getHeight())); @@ -286,11 +287,11 @@ const double AutoLayoutCentroidNode::calculateWidth() { if (reaction && reaction->isSetName() && _useNameAsTextLabel) displayedText = reaction->getName(); - return std::max(LIBSBMLNETWORK_CPP_NAMESPACE::getReactionDefaultWidth(), displayedText.size() * 9.0); + return std::max(LIBSBMLNETWORK_CPP_NAMESPACE::defaults_getReactionDefaultWidth(), displayedText.size() * 9.0); } const double AutoLayoutCentroidNode::calculateHeight() { - return std::max(LIBSBMLNETWORK_CPP_NAMESPACE::getReactionDefaultHeight(), getHeight()); + return std::max(LIBSBMLNETWORK_CPP_NAMESPACE::defaults_getReactionDefaultHeight(), getHeight()); } const bool AutoLayoutCentroidNode::isSetCurve() { diff --git a/src/autolayout/libsbmlnetwork_autolayout_node.h b/src/features/autolayout/libsbmlnetwork_autolayout_node.h similarity index 92% rename from src/autolayout/libsbmlnetwork_autolayout_node.h rename to src/features/autolayout/libsbmlnetwork_autolayout_node.h index 9a9d1f5..ba209d3 100644 --- a/src/autolayout/libsbmlnetwork_autolayout_node.h +++ b/src/features/autolayout/libsbmlnetwork_autolayout_node.h @@ -7,7 +7,7 @@ class AutoLayoutNodeBase : public AutoLayoutObjectBase { public: - AutoLayoutNodeBase(Model* model, Layout* layout, GraphicalObject* graphicalObject, const bool& useNameAsTextLabel, const bool& locked = false); + AutoLayoutNodeBase(Model* model, Layout* layout, GraphicalObject* graphicalObject, const bool& useNameAsTextLabel, const bool& positionFixed = false); virtual GraphicalObject* getGraphicalObject() = 0; @@ -57,18 +57,18 @@ class AutoLayoutNodeBase : public AutoLayoutObjectBase { void incrementDegree(); - void updateLockedStatus(); + void updateFixedPositionStatus(); - const bool isLocked(); + const bool isPositionFixed(); - void setLocked(const bool& locked); + void setPositionFixed(const bool& positionFixed); protected: double _displacementX; double _displacementY; int _degree; - bool _locked; + bool _positionFixed; bool _useNameAsTextLabel; GraphicalObject* _graphicalObject; }; @@ -76,7 +76,7 @@ class AutoLayoutNodeBase : public AutoLayoutObjectBase { class AutoLayoutNode : public AutoLayoutNodeBase { public: - AutoLayoutNode(Model* model, Layout* layout, GraphicalObject* graphicalObject, const bool& useNameAsTextLabel, const bool& locked = false); + AutoLayoutNode(Model* model, Layout* layout, GraphicalObject* graphicalObject, const bool& useNameAsTextLabel, const bool& positionFixed = false); const std::string getId() override; @@ -112,7 +112,7 @@ class AutoLayoutNode : public AutoLayoutNodeBase { class AutoLayoutCentroidNode : public AutoLayoutNodeBase { public: - AutoLayoutCentroidNode(Model* model, Layout* layout, GraphicalObject* graphicalObject, const bool& useNameAsTextLabel, const bool& locked = false); + AutoLayoutCentroidNode(Model* model, Layout* layout, GraphicalObject* graphicalObject, const bool& useNameAsTextLabel, const bool& positionFixed = false); const std::string getId() override; diff --git a/src/autolayout/libsbmlnetwork_autolayout_object_base.cpp b/src/features/autolayout/libsbmlnetwork_autolayout_object_base.cpp similarity index 100% rename from src/autolayout/libsbmlnetwork_autolayout_object_base.cpp rename to src/features/autolayout/libsbmlnetwork_autolayout_object_base.cpp diff --git a/src/autolayout/libsbmlnetwork_autolayout_object_base.h b/src/features/autolayout/libsbmlnetwork_autolayout_object_base.h similarity index 100% rename from src/autolayout/libsbmlnetwork_autolayout_object_base.h rename to src/features/autolayout/libsbmlnetwork_autolayout_object_base.h diff --git a/src/autolayout/libsbmlnetwork_autolayout_point.cpp b/src/features/autolayout/libsbmlnetwork_autolayout_point.cpp similarity index 100% rename from src/autolayout/libsbmlnetwork_autolayout_point.cpp rename to src/features/autolayout/libsbmlnetwork_autolayout_point.cpp diff --git a/src/autolayout/libsbmlnetwork_autolayout_point.h b/src/features/autolayout/libsbmlnetwork_autolayout_point.h similarity index 100% rename from src/autolayout/libsbmlnetwork_autolayout_point.h rename to src/features/autolayout/libsbmlnetwork_autolayout_point.h diff --git a/src/autolayout/libsbmlnetwork_fruchterman_reingold_algorithm.cpp b/src/features/autolayout/libsbmlnetwork_fruchterman_reingold_algorithm.cpp similarity index 95% rename from src/autolayout/libsbmlnetwork_fruchterman_reingold_algorithm.cpp rename to src/features/autolayout/libsbmlnetwork_fruchterman_reingold_algorithm.cpp index 581762a..c46067c 100644 --- a/src/autolayout/libsbmlnetwork_fruchterman_reingold_algorithm.cpp +++ b/src/features/autolayout/libsbmlnetwork_fruchterman_reingold_algorithm.cpp @@ -2,8 +2,9 @@ #include "libsbmlnetwork_autolayout_node.h" #include "libsbmlnetwork_autolayout_connection.h" #include "libsbmlnetwork_autolayout_curve.h" -#include "../libsbmlnetwork_layout_helpers.h" -#include "../libsbmlnetwork_sbmldocument_helpers.h" +#include "../../libsbmlnetwork_layout_helpers.h" +#include "../user_data/libsbmlnetwork_user_data.h" +#include "../defaults/libsbmlnetwork_defaults_layout.h" #include #include @@ -66,9 +67,9 @@ void FruchtermanReingoldAlgorithmBase::setNodesDegrees() { } void FruchtermanReingoldAlgorithmBase::setWidth(Layout* layout) { - std::string width = LIBSBMLNETWORK_CPP_NAMESPACE::getUserData(layout->getDimensions(), "width"); + std::string width = LIBSBMLNETWORK_CPP_NAMESPACE::user_data_getUserData(layout->getDimensions(), "width"); if (!width.empty() && std::stod(width) > 0.0) { - _width = std::max(0.0, std::stod(width) - 6 * getDefaultAutoLayoutPadding()); + _width = std::max(0.0, std::stod(width) - 6 * defaults_getDefaultAutoLayoutPadding()); _useHorizontalBoundary = true; } else @@ -76,9 +77,9 @@ void FruchtermanReingoldAlgorithmBase::setWidth(Layout* layout) { } void FruchtermanReingoldAlgorithmBase::setHeight(Layout* layout) { - std::string height = LIBSBMLNETWORK_CPP_NAMESPACE::getUserData(layout->getDimensions(), "height"); + std::string height = LIBSBMLNETWORK_CPP_NAMESPACE::user_data_getUserData(layout->getDimensions(), "height"); if (!height.empty() && std::stod(height) > 0.0) { - _height = std::max(0.0, std::stod(height) - 6 * getDefaultAutoLayoutPadding()); + _height = std::max(0.0, std::stod(height) - 6 * defaults_getDefaultAutoLayoutPadding()); _useVerticalBoundary = true; } else @@ -101,14 +102,14 @@ void FruchtermanReingoldAlgorithmBase::setUseGrid(const bool &useGrid) { _useGrid = useGrid; } -void FruchtermanReingoldAlgorithmBase::updateNodesLockedStatus() { +void FruchtermanReingoldAlgorithmBase::updateNodesFixedPositionStatus() { for (int i = 0; i < _nodes.size(); i++) - ((AutoLayoutNodeBase *) _nodes.at(i))->updateLockedStatus(); + ((AutoLayoutNodeBase *) _nodes.at(i))->updateFixedPositionStatus(); } -void FruchtermanReingoldAlgorithmBase::updateConnectionsLockedStatus() { +void FruchtermanReingoldAlgorithmBase::updateConnectionsFixedPositionStatus() { for (int i = 0; i < _connections.size(); i++) - ((AutoLayoutConnection *) _connections.at(i))->updateLockedStatus(); + ((AutoLayoutConnection *) _connections.at(i))->updateFixedPositionStatus(); } void FruchtermanReingoldAlgorithmBase::apply() { @@ -160,18 +161,18 @@ void FruchtermanReingoldAlgorithmBase::computeRepulsiveForces() { double distanceY = vNode->getY() - uNode->getY(); double distance = calculateEuclideanDistance(AutoLayoutPoint(distanceX, distanceY)); if (distance < 0.000001) { - if (!vNode->isLocked()) { + if (!vNode->isPositionFixed()) { vNode->setX(vNode->getX() + std::rand() % int(_stiffness)); vNode->setY(vNode->getY() + std::rand() % int(_stiffness)); } } else { double repulsionForce = calculateRepulsionForce(_stiffness * calculateStiffnessAdjustmentFactor(vNode, uNode), distance); - if (!vNode->isLocked()) { + if (!vNode->isPositionFixed()) { vNode->setDisplacementX(vNode->getDisplacementX() + (distanceX / distance * repulsionForce)); vNode->setDisplacementY(vNode->getDisplacementY() + (distanceY /distance * repulsionForce)); } - if (!uNode->isLocked()) { + if (!uNode->isPositionFixed()) { uNode->setDisplacementX(uNode->getDisplacementX() - (distanceX / distance * repulsionForce)); uNode->setDisplacementY(uNode->getDisplacementY() - (distanceY / distance * repulsionForce)); } @@ -196,11 +197,11 @@ void FruchtermanReingoldAlgorithmBase::computeAttractiveForces() { double distance = calculateEuclideanDistance(AutoLayoutPoint(distanceX, distanceY)); if (distance > 0.000001) { double attractionForce = calculateAttractionForce(_stiffness * calculateStiffnessAdjustmentFactor(vNode, uNode), distance); - if (!vNode->isLocked()) { + if (!vNode->isPositionFixed()) { vNode->setDisplacementX(vNode->getDisplacementX() - (distanceX / distance * attractionForce)); vNode->setDisplacementY(vNode->getDisplacementY() - (distanceY /distance * attractionForce)); } - if (!uNode->isLocked()) { + if (!uNode->isPositionFixed()) { uNode->setDisplacementX(uNode->getDisplacementX() + (distanceX / distance * attractionForce)); uNode->setDisplacementY(uNode->getDisplacementY() + (distanceY /distance * attractionForce)); } @@ -230,11 +231,11 @@ void FruchtermanReingoldAlgorithmBase::applyMagnetism() { double distance = calculateEuclideanDistance(AutoLayoutPoint(distanceX, distanceY)); if (distance > 0.000001) { double attractionForce = calculateAttractionForce(_stiffness * calculateStiffnessAdjustmentFactor(vNode, uNode), distance); - if (!vNode->isLocked()) { + if (!vNode->isPositionFixed()) { vNode->setDisplacementX(vNode->getDisplacementX() - 0.25 * (distanceX / distance * attractionForce)); vNode->setDisplacementY(vNode->getDisplacementY() - 0.25 * (distanceY /distance * attractionForce)); } - if (!uNode->isLocked()) { + if (!uNode->isPositionFixed()) { uNode->setDisplacementX(uNode->getDisplacementX() + 0.25 * (distanceX / distance * attractionForce)); uNode->setDisplacementY(uNode->getDisplacementY() + 0.25 * (distanceY /distance * attractionForce)); } @@ -252,7 +253,7 @@ void FruchtermanReingoldAlgorithmBase::applyGravity() { AutoLayoutNodeBase* node = NULL; for(int nodeIndex = 0; nodeIndex < _nodes.size(); nodeIndex++) { node = (AutoLayoutNodeBase*)_nodes.at(nodeIndex); - if (!node->isLocked()) { + if (!node->isPositionFixed()) { double distanceX = node->getX() - _barycenter.getX(); double distanceY = node->getY() - _barycenter.getY(); double distance = calculateEuclideanDistance(AutoLayoutPoint(distanceX, distanceY)); @@ -272,7 +273,7 @@ void FruchtermanReingoldAlgorithmBase::adjustCoordinates() { } void FruchtermanReingoldAlgorithmBase::adjustNodeCoordinates(AutoLayoutObjectBase* node) { - if (!((AutoLayoutNodeBase*)node)->isLocked()) { + if (!((AutoLayoutNodeBase*)node)->isPositionFixed()) { double distanceX = ((AutoLayoutNodeBase*)node)->getDisplacementX(); double distanceY = ((AutoLayoutNodeBase*)node)->getDisplacementY(); double distance = calculateEuclideanDistance(AutoLayoutPoint(distanceX, distanceY)); @@ -323,10 +324,10 @@ void FruchtermanReingoldAlgorithmBase::adjustCoordinateOrigin() { if (((AutoLayoutNodeBase*)_nodes.at(nodeIndex))->getY() < _origin.getY()) _origin.setY(((AutoLayoutNodeBase*)_nodes.at(nodeIndex))->getY()); } - _origin.setX(_origin.getX() - getDefaultAutoLayoutPadding()); - _origin.setY(_origin.getY() - getDefaultAutoLayoutPadding()); + _origin.setX(_origin.getX() - defaults_getDefaultAutoLayoutPadding()); + _origin.setY(_origin.getY() - defaults_getDefaultAutoLayoutPadding()); for (int nodeIndex = 0; nodeIndex < _nodes.size(); nodeIndex++) { - if (!((AutoLayoutNodeBase*)_nodes.at(nodeIndex))->isLocked()) { + if (!((AutoLayoutNodeBase*)_nodes.at(nodeIndex))->isPositionFixed()) { ((AutoLayoutNodeBase*)_nodes.at(nodeIndex))->setX(((AutoLayoutNodeBase*)_nodes.at(nodeIndex))->getX() - _origin.getX()); ((AutoLayoutNodeBase*)_nodes.at(nodeIndex))->setY(((AutoLayoutNodeBase*)_nodes.at(nodeIndex))->getY() - _origin.getY()); } @@ -420,7 +421,7 @@ void FruchtermanReingoldAlgorithmBase::setCurvePoints(AutoLayoutObjectBase* conn for (int curveIndex = 0; curveIndex < ((AutoLayoutConnection*)connection)->getCurves().size(); curveIndex++) { curve = (AutoLayoutCurve*)(((AutoLayoutConnection*)connection)->getCurves().at(curveIndex)); curveNode = (AutoLayoutNodeBase*)findObject(_nodes, curve->getNodeId()); - if (!curve->isLocked() && curveNode) { + if (!curve->isPositionFixed() && curveNode) { curve->setNodeSidePoint(curveNode->getPosition()); curve->setNodeSideControlPoint(curveNode->getPosition()); curve->setCentroidSidePoint(centroidNode->getPosition()); @@ -461,12 +462,12 @@ void FruchtermanReingoldAlgorithmBase::setCurvePoints(AutoLayoutObjectBase* conn void FruchtermanReingoldAlgorithmBase::adjustCurvePoints(AutoLayoutObjectBase* connection) { for (int firstCurveIndex = 0; firstCurveIndex < ((AutoLayoutConnection*)connection)->getCurves().size(); firstCurveIndex++) { AutoLayoutCurve* firstCurve = (AutoLayoutCurve*)(((AutoLayoutConnection*)connection)->getCurves().at(firstCurveIndex)); - if (!firstCurve->isLocked()) { + if (!firstCurve->isPositionFixed()) { AutoLayoutNodeBase* firstCurveNode = (AutoLayoutNodeBase*)findObject(_nodes, firstCurve->getNodeId()); if (firstCurveNode) { for (int secondCurveIndex = firstCurveIndex + 1; secondCurveIndex < ((AutoLayoutConnection*)connection)->getCurves().size(); secondCurveIndex++) { AutoLayoutCurve* secondCurve = (AutoLayoutCurve*)(((AutoLayoutConnection*)connection)->getCurves().at(secondCurveIndex)); - if (!secondCurve->isLocked()) { + if (!secondCurve->isPositionFixed()) { AutoLayoutNodeBase* secondCurveNode = (AutoLayoutNodeBase*)findObject(_nodes, secondCurve->getNodeId()); if (firstCurve->getNodeId() == secondCurve->getNodeId() ) { if (firstCurve->getRole() == secondCurve->getRole()) { @@ -488,7 +489,7 @@ void FruchtermanReingoldAlgorithmBase::adjustCurvePoints(AutoLayoutObjectBase* c } void FruchtermanReingoldAlgorithmBase::adjustUniUniConnections(AutoLayoutObjectBase* connection) { - if (!((AutoLayoutNodeBase*)((AutoLayoutConnection*)connection)->getCentroidNode())->isLocked()) { + if (!((AutoLayoutNodeBase*)((AutoLayoutConnection*)connection)->getCentroidNode())->isPositionFixed()) { std::vector nodeIds = ((AutoLayoutConnection*)connection)->getNodeIds(); double slope = getNodePairSlope(_nodes, nodeIds.at(0), nodeIds.at(1)); if (slope < 0.0) diff --git a/src/autolayout/libsbmlnetwork_fruchterman_reingold_algorithm.h b/src/features/autolayout/libsbmlnetwork_fruchterman_reingold_algorithm.h similarity index 98% rename from src/autolayout/libsbmlnetwork_fruchterman_reingold_algorithm.h rename to src/features/autolayout/libsbmlnetwork_fruchterman_reingold_algorithm.h index 8059042..e69e57f 100644 --- a/src/autolayout/libsbmlnetwork_fruchterman_reingold_algorithm.h +++ b/src/features/autolayout/libsbmlnetwork_fruchterman_reingold_algorithm.h @@ -40,11 +40,11 @@ class FruchtermanReingoldAlgorithmBase { void setUseGrid(const bool& useGrid); - void updateNodesLockedStatus(); + void updateNodesFixedPositionStatus(); - void updateConnectionsLockedStatus(); + void updateConnectionsFixedPositionStatus(); - void lockNodes(); + void fixedPositionNodes(); void apply(); diff --git a/src/colors/libsbmlnetwork_colors.cpp b/src/features/colors/libsbmlnetwork_colors.cpp similarity index 99% rename from src/colors/libsbmlnetwork_colors.cpp rename to src/features/colors/libsbmlnetwork_colors.cpp index 78a4b84..45b6d6e 100644 --- a/src/colors/libsbmlnetwork_colors.cpp +++ b/src/features/colors/libsbmlnetwork_colors.cpp @@ -1,5 +1,5 @@ #include "libsbmlnetwork_colors.h" -#include "../libsbmlnetwork_common.h" +#include "../../libsbmlnetwork_common.h" namespace LIBSBMLNETWORK_CPP_NAMESPACE { diff --git a/src/colors/libsbmlnetwork_colors.h b/src/features/colors/libsbmlnetwork_colors.h similarity index 100% rename from src/colors/libsbmlnetwork_colors.h rename to src/features/colors/libsbmlnetwork_colors.h diff --git a/src/features/defaults/libsbmlnetwork_defaults_layout.cpp b/src/features/defaults/libsbmlnetwork_defaults_layout.cpp new file mode 100644 index 0000000..e810655 --- /dev/null +++ b/src/features/defaults/libsbmlnetwork_defaults_layout.cpp @@ -0,0 +1,65 @@ +#include "libsbmlnetwork_defaults_layout.h" + +namespace LIBSBMLNETWORK_CPP_NAMESPACE { + +void defaults_setDefaultLayoutId(Layout* layout) { + if (!layout->isSetId()) + layout->setId(defaults_getDefaultLayoutId()); +} + +const std::string defaults_getDefaultLayoutId() { + return "libSBMLNetwork_Layout"; +} + +void defaults_setDefaultLayoutDimensions(Layout* layout) { + Dimensions* dimensions = layout->getDimensions(); + if (!dimensions) { + dimensions = new Dimensions(layout->getLevel(), layout->getVersion(), layout->getPackageVersion()); + layout->setDimensions(dimensions); + } + if (dimensions->getWidth() < 0.0001) + dimensions->setWidth(1024.0); + if (dimensions->getHeight() < 0.0001) + dimensions->setHeight(1024.0); +} + +CompartmentGlyph* defaults_getDefaultCompartmentGlyph(Layout* layout) { + if (layout->getNumCompartmentGlyphs() == 1 && layout->getCompartmentGlyph(0)->getCompartmentId() == "default_compartment") + return layout->getCompartmentGlyph(0); + + return NULL; +} + +const double defaults_getSpeciesDefaultWidth() { + return 60.0; +} + +const double defaults_getSpeciesDefaultHeight() { + return 36.0; +} + +const double defaults_getEmptySpeciesDefaultRadius() { + return 15.0; +} + +const double defaults_getReactionDefaultWidth() { + return 30.0; +} + +const double defaults_getReactionDefaultHeight() { + return 20.0; +} + +const double defaults_getDefaultAutoLayoutPadding() { + return 30.0; +} + +const double defaults_getAliasSpeciesGlyphPadding() { + return 30.0; +} + +const double defaults_getAliasReactionGlyphPadding() { + return 30.0; +} + +} diff --git a/src/features/defaults/libsbmlnetwork_defaults_layout.h b/src/features/defaults/libsbmlnetwork_defaults_layout.h new file mode 100644 index 0000000..fb62786 --- /dev/null +++ b/src/features/defaults/libsbmlnetwork_defaults_layout.h @@ -0,0 +1,39 @@ +#ifndef __LIBSBMLNETWORK_DEFAULTS_H +#define __LIBSBMLNETWORK_DEFAULTS_H + +#ifndef SWIG +#include "sbml/SBMLTypes.h" +#include "sbml/packages/layout/common/LayoutExtensionTypes.h" +#endif + +using namespace libsbml; + +namespace LIBSBMLNETWORK_CPP_NAMESPACE { + +void defaults_setDefaultLayoutId(Layout* layout); + +const std::string defaults_getDefaultLayoutId(); + +void defaults_setDefaultLayoutDimensions(Layout* layout); + +CompartmentGlyph* defaults_getDefaultCompartmentGlyph(Layout* layout); + +const double defaults_getSpeciesDefaultWidth(); + +const double defaults_getSpeciesDefaultHeight(); + +const double defaults_getEmptySpeciesDefaultRadius(); + +const double defaults_getReactionDefaultWidth(); + +const double defaults_getReactionDefaultHeight(); + +const double defaults_getDefaultAutoLayoutPadding(); + +const double defaults_getAliasSpeciesGlyphPadding(); + +const double defaults_getAliasReactionGlyphPadding(); + +} + +#endif diff --git a/src/features/defaults/libsbmlnetwork_defaults_render.cpp b/src/features/defaults/libsbmlnetwork_defaults_render.cpp new file mode 100644 index 0000000..216a8c5 --- /dev/null +++ b/src/features/defaults/libsbmlnetwork_defaults_render.cpp @@ -0,0 +1,223 @@ +#include "libsbmlnetwork_defaults_render.h" +#include "../../libsbmlnetwork_render_helpers.h" + +#include + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + +namespace LIBSBMLNETWORK_CPP_NAMESPACE { + + void defaults_addDefaultColors(GlobalRenderInformation* globalRenderInformation) { + addColor(globalRenderInformation, "white"); + addColor(globalRenderInformation, "black"); + addColor(globalRenderInformation, "lightgray"); + addColor(globalRenderInformation, "darkslategray"); + addColor(globalRenderInformation, "darkcyan"); + addColor(globalRenderInformation, "teal"); + addColor(globalRenderInformation, "silver"); + } + + void defaults_addColorsOfDefaultGeometricShapes(SBMLDocument* document, Style* style) { + addColor(document, style, "white"); + addColor(document, style, "black"); + } + + void defaults_addColorsOfDefaultGeometricShapes(GlobalRenderInformation* globalRenderInformation) { + addColor(globalRenderInformation, "white"); + addColor(globalRenderInformation, "black"); + } + + void defaults_addDefaultLineEndings(GlobalRenderInformation* globalRenderInformation) { + addProductHeadLineEnding(globalRenderInformation); + addModifierHeadLineEnding(globalRenderInformation); + addActivatorHeadLineEnding(globalRenderInformation); + addInhibitorHeadLineEnding(globalRenderInformation); + } + + void defaults_setDefault1DShapeFeatures(GraphicalPrimitive1D* graphicalPrimitive1D) { + graphicalPrimitive1D->setStroke("black"); + graphicalPrimitive1D->setStrokeWidth(2.0); + } + + void defaults_setDefault2DShapeFeatures(GraphicalPrimitive2D* graphicalPrimitive2D) { + defaults_setDefault1DShapeFeatures(graphicalPrimitive2D); + graphicalPrimitive2D->setFill("white"); + } + + void defaults_setDefaultRectangleShapeFeatures(Rectangle* rectangle) { + defaults_setDefault2DShapeFeatures(rectangle); + rectangle->setX(RelAbsVector(0.0, 0.0)); + rectangle->setY(RelAbsVector(0.0, 0.0)); + rectangle->setWidth(RelAbsVector(0.0, 100.0)); + rectangle->setHeight(RelAbsVector(0.0, 100.0)); + rectangle->setRX(RelAbsVector(0.0, 10.0)); + rectangle->setRY(RelAbsVector(0.0, 10.0)); + } + + void defaults_setDefaultSquareShapeFeatures(Rectangle* square) { + defaults_setDefault2DShapeFeatures(square); + square->setX(RelAbsVector(0.0, 0.0)); + square->setY(RelAbsVector(0.0, 0.0)); + square->setWidth(RelAbsVector(0.0, 100.0)); + square->setRatio(1.0); + square->setRX(RelAbsVector(0.0, 0.0)); + square->setRY(RelAbsVector(0.0, 0.0)); + } + + void defaults_setDefaultEllipseShapeFeatures(Ellipse* ellipse) { + defaults_setDefault2DShapeFeatures(ellipse); + ellipse->setCX(RelAbsVector(0.0, 50.0)); + ellipse->setCY(RelAbsVector(0.0, 50.0)); + ellipse->setRX(RelAbsVector(0.0, 50.0)); + ellipse->setRY(RelAbsVector(0.0, 50.0)); + ellipse->setStroke("black"); + ellipse->setStrokeWidth(2.0); + } + + void defaults_setDefaultCircleShapeFeatures(Ellipse* circle) { + defaults_setDefault2DShapeFeatures(circle); + circle->setCX(RelAbsVector(0.0, 50.0)); + circle->setCY(RelAbsVector(0.0, 50.0)); + circle->setRX(RelAbsVector(0.0, 50.0)); + circle->setRatio(1.0); + circle->setStroke("black"); + circle->setStrokeWidth(2.0); + } + + void defaults_setDefaultTriangleShapeFeatures(Polygon* triangle) { + defaults_setDefault2DShapeFeatures(triangle); + RenderPoint* point = NULL; + point = triangle->createPoint(); + point->setX(RelAbsVector(0.0, 0.0)); + point->setY(RelAbsVector(0.0, 0.0)); + point = triangle->createPoint(); + point->setX(RelAbsVector(0.0, 100.0)); + point->setY(RelAbsVector(0.0, 0.0)); + point = triangle->createPoint(); + point->setX(RelAbsVector(0.0, 50.0)); + point->setY(RelAbsVector(0.0, 100.0)); + } + + void defaults_setDefaultDiamondShapeFeatures(Polygon* diamond) { + defaults_setDefault2DShapeFeatures(diamond); + RenderPoint* point = NULL; + point = diamond->createPoint(); + point->setX(RelAbsVector(0.0, 0.0)); + point->setY(RelAbsVector(0.0, 50.0)); + point = diamond->createPoint(); + point->setX(RelAbsVector(0.0, 50.0)); + point->setY(RelAbsVector(0.0, 0.0)); + point = diamond->createPoint(); + point->setX(RelAbsVector(0.0, 100.0)); + point->setY(RelAbsVector(0.0, 50.0)); + point = diamond->createPoint(); + point->setX(RelAbsVector(0.0, 50.0)); + point->setY(RelAbsVector(0.0, 100.0)); + + } + + void defaults_setDefaultPentagonShapeFeatures(Polygon* pentagon) { + defaults_setDefault2DShapeFeatures(pentagon); + RenderPoint* point = NULL; + point = pentagon->createPoint(); + point->setX(RelAbsVector(0.0, 50. * (1 - std::sin(0.4 * M_PI)))); + point->setY(RelAbsVector(0.0, 50. * (1 - std::cos(0.4 * M_PI)))); + point = pentagon->createPoint(); + point->setX(RelAbsVector(0.0, 50.)); + point->setY(RelAbsVector(0.0, 0.)); + point = pentagon->createPoint(); + point->setX(RelAbsVector(0.0, 50. * (1 + std::sin(0.4 * M_PI)))); + point->setY(RelAbsVector(0.0, 50. * (1 - std::cos(0.4 * M_PI)))); + point = pentagon->createPoint(); + point->setX(RelAbsVector(0.0, 50. * (1 + std::sin(0.2 * M_PI)))); + point->setY(RelAbsVector(0.0, 50. * (1 + std::cos(0.2 * M_PI)))); + point = pentagon->createPoint(); + point->setX(RelAbsVector(0.0, 50. * (1 - std::sin(0.2 * M_PI)))); + point->setY(RelAbsVector(0.0, 50. * (1 + std::cos(0.2 * M_PI)))); + } + + void defaults_setDefaultHexagonShapeFeatures(Polygon* hexagon) { + defaults_setDefault2DShapeFeatures(hexagon); + RenderPoint* point = NULL; + point = hexagon->createPoint(); + point->setX(RelAbsVector(0.0, 0.0)); + point->setY(RelAbsVector(0.0, 25.0)); + point = hexagon->createPoint(); + point->setX(RelAbsVector(0.0, 50.0)); + point->setY(RelAbsVector(0.0, 0.0)); + point = hexagon->createPoint(); + point->setX(RelAbsVector(0.0, 100.0)); + point->setY(RelAbsVector(0.0, 25.0)); + point = hexagon->createPoint(); + point->setX(RelAbsVector(0.0, 100.0)); + point->setY(RelAbsVector(0.0, 75.0)); + point = hexagon->createPoint(); + point->setX(RelAbsVector(0.0, 50.0)); + point->setY(RelAbsVector(0.0, 100.0)); + point = hexagon->createPoint(); + point->setX(RelAbsVector(0.0, 0.0)); + point->setY(RelAbsVector(0.0, 75.0)); + } + + void defaults_setDefaultOctagonShapeFeatures(Polygon* octagon) { + defaults_setDefault2DShapeFeatures(octagon); + const double pi = 3.14159265; + RenderPoint* point = NULL; + point = octagon->createPoint(); + point->setX(RelAbsVector(0.0, 0.0)); + point->setY(RelAbsVector(0.0, 50.0)); + point = octagon->createPoint(); + point->setX(RelAbsVector(0.0, 50. * (1 - std::cos(M_PI / 4.0)))); + point->setY(RelAbsVector(0.0, 50. * (1 - std::sin(M_PI / 4.0)))); + point = octagon->createPoint(); + point->setX(RelAbsVector(0.0, 50.0)); + point->setY(RelAbsVector(0.0, 0.0)); + point = octagon->createPoint(); + point->setX(RelAbsVector(0.0, 50. * (1 + std::cos(M_PI / 4.0)))); + point->setY(RelAbsVector(0.0, 50. * (1 - std::sin(M_PI / 4.0)))); + point = octagon->createPoint(); + point->setX(RelAbsVector(0.0, 100.0)); + point->setY(RelAbsVector(0.0, 50.0)); + point = octagon->createPoint(); + point->setX(RelAbsVector(0.0, 50. * (1 + std::cos(M_PI / 4.0)))); + point->setY(RelAbsVector(0.0, 50. * (1 + std::sin(M_PI / 4.0)))); + point = octagon->createPoint(); + point->setX(RelAbsVector(0.0, 50.0)); + point->setY(RelAbsVector(0.0, 100.0)); + point = octagon->createPoint(); + point->setX(RelAbsVector(0.0, 50. * (1 - std::cos(M_PI / 4.0)))); + point->setY(RelAbsVector(0.0, 50. * (1 + std::sin(M_PI / 4.0)))); + } + + void defaults_setDefaultRenderCurveShapeFeatures(RenderCurve* renderCurve) { + defaults_setDefault1DShapeFeatures(renderCurve); + RenderPoint* point = NULL; + point = renderCurve->createPoint(); + point->setX(RelAbsVector(0.0, 0.0)); + point->setY(RelAbsVector(0.0, 50.0)); + point = renderCurve->createPoint(); + point->setX(RelAbsVector(0.0, 100.0)); + point->setY(RelAbsVector(0.0, 50.0)); + } + + void defaults_setDefaultImageShapeFeatures(Image* image) { + image->setX(RelAbsVector(0.0, 0.0)); + image->setY(RelAbsVector(0.0, 0.0)); + image->setWidth(RelAbsVector(0.0, 100.0)); + image->setHeight(RelAbsVector(0.0, 100.0)); + } + + void defaults_setDefaultDiagonalRenderCurveFeatures(RenderCurve* renderCurve) { + defaults_setDefault1DShapeFeatures(renderCurve); + RenderPoint* point = NULL; + point = renderCurve->createPoint(); + point->setX(RelAbsVector(0.0, 100.0)); + point->setY(RelAbsVector(0.0, 0.0)); + point = renderCurve->createPoint(); + point->setX(RelAbsVector(0.0, 0.0)); + point->setY(RelAbsVector(0.0, 100.0)); + } + +} diff --git a/src/features/defaults/libsbmlnetwork_defaults_render.h b/src/features/defaults/libsbmlnetwork_defaults_render.h new file mode 100644 index 0000000..30ccd5d --- /dev/null +++ b/src/features/defaults/libsbmlnetwork_defaults_render.h @@ -0,0 +1,50 @@ +#ifndef __LIBSBMLNETWORK_DEFAULTS_RENDER_H +#define __LIBSBMLNETWORK_DEFAULTS_RENDER_H + +#ifndef SWIG +#include "sbml/SBMLTypes.h" +#include "sbml/packages/render/common/RenderExtensionTypes.h" +#endif + +using namespace libsbml; + +namespace LIBSBMLNETWORK_CPP_NAMESPACE { + + void defaults_addDefaultColors(GlobalRenderInformation* globalRenderInformation); + + void defaults_addColorsOfDefaultGeometricShapes(SBMLDocument* document, Style* style); + + void defaults_addColorsOfDefaultGeometricShapes(GlobalRenderInformation* globalRenderInformation); + + void defaults_addDefaultLineEndings(GlobalRenderInformation* globalRenderInformation); + + void defaults_setDefault1DShapeFeatures(GraphicalPrimitive1D* graphicalPrimitive1D); + + void defaults_setDefault2DShapeFeatures(GraphicalPrimitive2D* graphicalPrimitive2D); + + void defaults_setDefaultRectangleShapeFeatures(Rectangle* rectangle); + + void defaults_setDefaultSquareShapeFeatures(Rectangle* square); + + void defaults_setDefaultEllipseShapeFeatures(Ellipse* ellipse); + + void defaults_setDefaultCircleShapeFeatures(Ellipse* circle); + + void defaults_setDefaultTriangleShapeFeatures(Polygon* triangle); + + void defaults_setDefaultDiamondShapeFeatures(Polygon* diamond); + + void defaults_setDefaultPentagonShapeFeatures(Polygon* pentagon); + + void defaults_setDefaultHexagonShapeFeatures(Polygon* pentagon); + + void defaults_setDefaultOctagonShapeFeatures(Polygon* pentagon); + + void defaults_setDefaultRenderCurveShapeFeatures(RenderCurve* renderCurve); + + void defaults_setDefaultImageShapeFeatures(Image* image); + + void defaults_setDefaultDiagonalRenderCurveFeatures(RenderCurve* renderCurve); +} + +#endif diff --git a/src/features/error_log/libsbmlnetwork_error_log.cpp b/src/features/error_log/libsbmlnetwork_error_log.cpp new file mode 100644 index 0000000..9c676f7 --- /dev/null +++ b/src/features/error_log/libsbmlnetwork_error_log.cpp @@ -0,0 +1,360 @@ +#include "libsbmlnetwork_error_log.h" +#include "../../libsbmlnetwork_layout_helpers.h" +#include "../../libsbmlnetwork_layout.h" +#include "../../libsbmlnetwork_sbmldocument_layout.h" +#include "../../libsbmlnetwork_render.h" +#include "../../libsbmlnetwork_render_helpers.h" +#include "../../libsbmlnetwork_sbmldocument_render.h" +#include "../../libsbmlnetwork_layout_render.h" +#include "../../features/user_data/libsbmlnetwork_user_data.h" + +namespace LIBSBMLNETWORK_CPP_NAMESPACE { + +const std::string error_log_getErrorLog(SBMLDocument* document) { + std::string errorLog = ""; + if (document) { + errorLog = error_log_prepareErrorMessage(user_data_getUserData(document, "error_log"), errorLog); + ListOfLayouts* listOfLayouts = getListOfLayouts(document); + errorLog += error_log_prepareErrorMessage(error_log_getErrorLog(listOfLayouts), errorLog); + const int numLayouts = getNumLayouts(document); + for (int i = 0; i < numLayouts; i++) { + Layout* layout = getLayout(document, i); + errorLog += error_log_prepareErrorMessage(error_log_getErrorLog(layout), errorLog); + const int numLocalRenderInformation = getNumLocalRenderInformation(layout); + for (int j = 0; j < numLocalRenderInformation; j++) + errorLog += error_log_prepareErrorMessage(error_log_getErrorLog(getLocalRenderInformation(layout, j)), errorLog); + + } + const int numGlobalRenderInformation = getNumGlobalRenderInformation(document); + for (int i = 0; i < numGlobalRenderInformation; i++) + errorLog += error_log_prepareErrorMessage(error_log_getErrorLog(getGlobalRenderInformation(document, i)), errorLog); + } + + return errorLog; +} + +void error_log_clearErrorLog(SBMLDocument* document) { + if (document) { + user_data_setUserData(document, "error_log", ""); + ListOfLayouts* listOfLayouts = getListOfLayouts(document); + error_log_clearErrorLog(listOfLayouts); + const int numLayouts = getNumLayouts(document); + for (int i = 0; i < numLayouts; i++) { + Layout* layout = getLayout(document, i); + error_log_clearErrorLog(layout); + const int numLocalRenderInformation = getNumLocalRenderInformation(layout); + for (int j = 0; j < numLocalRenderInformation; j++) + error_log_clearErrorLog(getLocalRenderInformation(layout, j)); + } + const int numGlobalRenderInformation = getNumGlobalRenderInformation(document); + for (int i = 0; i < numGlobalRenderInformation; i++) + error_log_clearErrorLog(getGlobalRenderInformation(document, i)); + } +} + +const std::string error_log_getErrorLog(Layout* layout) { + std::string errorLog = ""; + if (layout) { + errorLog += error_log_prepareErrorMessage(user_data_getUserData(layout, "error_log"), errorLog); + for (unsigned int i = 0; i < layout->getNumCompartmentGlyphs(); i++) + errorLog += error_log_prepareErrorMessage(error_log_getErrorLog(layout->getCompartmentGlyph(i)), errorLog); + for (unsigned int i = 0; i < layout->getNumSpeciesGlyphs(); i++) + errorLog += error_log_prepareErrorMessage(error_log_getErrorLog(layout->getSpeciesGlyph(i)), errorLog); + for (unsigned int i = 0; i < layout->getNumReactionGlyphs(); i++) { + errorLog += error_log_prepareErrorMessage(error_log_getErrorLog(layout->getReactionGlyph(i)), errorLog); + for (unsigned int j = 0; j < layout->getReactionGlyph(i)->getNumSpeciesReferenceGlyphs(); j++) + errorLog += error_log_prepareErrorMessage(error_log_getErrorLog(layout->getReactionGlyph(i)->getSpeciesReferenceGlyph(j)), errorLog); + } + for (unsigned int i = 0; i < layout->getNumTextGlyphs(); i++) + errorLog += error_log_prepareErrorMessage(error_log_getErrorLog(layout->getTextGlyph(i)), errorLog); + } + + return errorLog; +} + +void error_log_clearErrorLog(Layout* layout) { + if (layout) { + user_data_setUserData(layout, "error_log", ""); + for (unsigned int i = 0; i < layout->getNumCompartmentGlyphs(); i++) + error_log_clearErrorLog(layout->getCompartmentGlyph(i)); + for (unsigned int i = 0; i < layout->getNumSpeciesGlyphs(); i++) + error_log_clearErrorLog(layout->getSpeciesGlyph(i)); + for (unsigned int i = 0; i < layout->getNumReactionGlyphs(); i++) { + error_log_clearErrorLog(layout->getReactionGlyph(i)); + for (unsigned int j = 0; j < layout->getReactionGlyph(i)->getNumSpeciesReferenceGlyphs(); j++) + error_log_clearErrorLog(layout->getReactionGlyph(i)->getSpeciesReferenceGlyph(j)); + } + for (unsigned int i = 0; i < layout->getNumTextGlyphs(); i++) + error_log_clearErrorLog(layout->getTextGlyph(i)); + } +} + +const std::string error_log_getErrorLog(GraphicalObject* graphicalObject) { + std::string errorLog = ""; + if (graphicalObject) + errorLog += error_log_prepareErrorMessage(user_data_getUserData(graphicalObject, "error_log"), errorLog); + if (graphicalObject->getBoundingBox()) + errorLog += error_log_prepareErrorMessage(error_log_getErrorLog(graphicalObject->getBoundingBox()), errorLog); + if (isSetCurve(graphicalObject)) + errorLog += error_log_prepareErrorMessage(error_log_getErrorLog(getCurve(graphicalObject)), errorLog); + + return errorLog; +} + +void error_log_clearErrorLog(GraphicalObject* graphicalObject) { + if (graphicalObject) { + user_data_setUserData(graphicalObject, "error_log", ""); + if (graphicalObject->getBoundingBox()) + error_log_clearErrorLog(graphicalObject->getBoundingBox()); + if (isSetCurve(graphicalObject)) + error_log_clearErrorLog(getCurve(graphicalObject)); + } +} + +const std::string error_log_getErrorLog(BoundingBox* boundingBox) { + std::string errorLog = ""; + if (boundingBox) + errorLog += error_log_prepareErrorMessage(user_data_getUserData(boundingBox, "error_log"), errorLog); + + return errorLog; +} + +void error_log_clearErrorLog(BoundingBox* boundingBox) { + if (boundingBox) + user_data_setUserData(boundingBox, "error_log", ""); +} + +const std::string error_log_getErrorLog(Curve* curve) { + std::string errorLog = ""; + if (curve) + errorLog += error_log_prepareErrorMessage(user_data_getUserData(curve, "error_log"), errorLog); + for (unsigned int i = 0; i < getNumCurveSegments(curve); i++) + errorLog += error_log_prepareErrorMessage(error_log_getErrorLog(getCurveSegment(curve, i)), errorLog); + + return errorLog; +} + +void error_log_clearErrorLog(Curve* curve) { + if (curve) { + user_data_setUserData(curve, "error_log", ""); + for (unsigned int i = 0; i < getNumCurveSegments(curve); i++) + error_log_clearErrorLog(getCurveSegment(curve, i)); + } +} + +const std::string error_log_getErrorLog(LineSegment* lineSegment) { + std::string errorLog = ""; + if (lineSegment) + errorLog += error_log_prepareErrorMessage(user_data_getUserData(lineSegment, "error_log"), errorLog); + + return errorLog; +} + +void error_log_clearErrorLog(LineSegment* lineSegment) { + if (lineSegment) + user_data_setUserData(lineSegment, "error_log", ""); +} + +const std::string error_log_getErrorLog(RenderInformationBase* renderInformation) { + std::string errorLog = ""; + if (renderInformation) + errorLog += error_log_prepareErrorMessage(user_data_getUserData(renderInformation, "error_log"), errorLog); + for (unsigned int i = 0; i < renderInformation->getNumColorDefinitions(); i++) + errorLog += error_log_prepareErrorMessage(error_log_getErrorLog(renderInformation->getColorDefinition(i)), errorLog); + for (unsigned int i = 0; i < renderInformation->getNumGradientDefinitions(); i++) { + GradientBase* gradientBase = renderInformation->getGradientDefinition(i); + errorLog += error_log_prepareErrorMessage(error_log_getErrorLog(gradientBase), errorLog); + for (unsigned int j = 0; j < gradientBase->getNumGradientStops(); j++) + errorLog += error_log_prepareErrorMessage(error_log_getErrorLog(gradientBase->getGradientStop(j)), errorLog); + } + for (unsigned int i = 0; i < renderInformation->getNumLineEndings(); i++) + errorLog += error_log_prepareErrorMessage(error_log_getErrorLog(renderInformation->getLineEnding(i)), errorLog); + if (renderInformation->isGlobalRenderInformation()) { + for (unsigned int i = 0; i < ((GlobalRenderInformation*)renderInformation)->getNumGlobalStyles(); i++) + errorLog += error_log_prepareErrorMessage(error_log_getErrorLog(((GlobalRenderInformation *) renderInformation)->getGlobalStyle(i)), errorLog); + } + else if (renderInformation->isLocalRenderInformation()) { + for (unsigned int i = 0; i < ((LocalRenderInformation*)renderInformation)->getNumLocalStyles(); i++) + errorLog += error_log_prepareErrorMessage(error_log_getErrorLog(((LocalRenderInformation *) renderInformation)->getLocalStyle(i)), errorLog); + } + + return errorLog; +} + +void error_log_clearErrorLog(RenderInformationBase* renderInformation) { + if (renderInformation) { + user_data_setUserData(renderInformation, "error_log", ""); + for (unsigned int i = 0; i < renderInformation->getNumColorDefinitions(); i++) + error_log_clearErrorLog(renderInformation->getColorDefinition(i)); + for (unsigned int i = 0; i < renderInformation->getNumGradientDefinitions(); i++) { + GradientBase* gradientBase = renderInformation->getGradientDefinition(i); + error_log_clearErrorLog(gradientBase); + for (unsigned int j = 0; j < gradientBase->getNumGradientStops(); j++) + error_log_clearErrorLog(gradientBase->getGradientStop(j)); + } + for (unsigned int i = 0; i < renderInformation->getNumLineEndings(); i++) + error_log_clearErrorLog(renderInformation->getLineEnding(i)); + if (renderInformation->isGlobalRenderInformation()) { + for (unsigned int i = 0; i < ((GlobalRenderInformation*)renderInformation)->getNumGlobalStyles(); i++) + error_log_clearErrorLog(((GlobalRenderInformation*)renderInformation)->getGlobalStyle(i)); + } + else if (renderInformation->isLocalRenderInformation()) { + for (unsigned int i = 0; i < ((LocalRenderInformation*)renderInformation)->getNumLocalStyles(); i++) + error_log_clearErrorLog(((LocalRenderInformation*)renderInformation)->getLocalStyle(i)); + } + } +} + +const std::string error_log_getErrorLog(ColorDefinition* colorDefinition) { + std::string errorLog = ""; + if (colorDefinition) + errorLog += error_log_prepareErrorMessage(user_data_getUserData(colorDefinition, "error_log"), errorLog); + + return errorLog; +} + +void error_log_clearErrorLog(ColorDefinition* colorDefinition) { + if (colorDefinition) + user_data_setUserData(colorDefinition, "error_log", ""); +} + +const std::string error_log_getErrorLog(GradientBase* gradientBase) { + std::string errorLog = ""; + if (gradientBase) + errorLog += error_log_prepareErrorMessage(user_data_getUserData(gradientBase, "error_log"), errorLog); + + return errorLog; +} + +void error_log_clearErrorLog(GradientBase* gradientBase) { + if (gradientBase) + user_data_setUserData(gradientBase, "error_log", ""); +} + +const std::string error_log_getErrorLog(GradientStop* gradientStop) { + std::string errorLog = ""; + if (gradientStop) + errorLog += error_log_prepareErrorMessage(user_data_getUserData(gradientStop, "error_log"), errorLog); + + return errorLog; +} + +void error_log_clearErrorLog(GradientStop* gradientStop) { + if (gradientStop) + user_data_setUserData(gradientStop, "error_log", ""); +} + +const std::string error_log_getErrorLog(LineEnding* lineEnding) { + std::string errorLog = ""; + if (lineEnding) + errorLog += error_log_prepareErrorMessage(user_data_getUserData(lineEnding, "error_log"), errorLog); + + return errorLog; +} + +void error_log_clearErrorLog(LineEnding* lineEnding) { + if (lineEnding) + user_data_setUserData(lineEnding, "error_log", ""); +} + +const std::string error_log_getErrorLog(Style* style) { + std::string errorLog = ""; + if (style) { + errorLog += error_log_prepareErrorMessage(user_data_getUserData(style, "error_log"), errorLog); + errorLog += error_log_prepareErrorMessage(error_log_getErrorLog(style->getGroup()), errorLog); + } + + return errorLog; +} + +void error_log_clearErrorLog(Style* style) { + if (style) { + user_data_setUserData(style, "error_log", ""); + error_log_clearErrorLog( style->getGroup()); + } +} + +const std::string error_log_getErrorLog(RenderGroup* renderGroup) { + std::string errorLog = ""; + if (renderGroup) { + errorLog += error_log_prepareErrorMessage(user_data_getUserData(renderGroup, "error_log"), errorLog); + for (unsigned int i = 0; i < renderGroup->getNumElements(); i++) + errorLog += error_log_prepareErrorMessage(error_log_getErrorLog(renderGroup->getElement(i)), errorLog); + } + + return errorLog; +} + +void error_log_clearErrorLog(RenderGroup* renderGroup) { + if (renderGroup) { + user_data_setUserData(renderGroup, "error_log", ""); + for (unsigned int j = 0; j < renderGroup->getNumElements(); j++) + error_log_clearErrorLog(renderGroup->getElement(j)); + } +} + +const std::string error_log_getErrorLog(Transformation2D* transformation2D) { + std::string errorLog = ""; + if (transformation2D) + errorLog += error_log_prepareErrorMessage(user_data_getUserData(transformation2D, "error_log"), errorLog); + + return errorLog; +} + +void error_log_clearErrorLog(Transformation2D* transformation2D) { + if (transformation2D) + user_data_setUserData(transformation2D, "error_log", ""); +} + +const std::string error_log_getErrorLog(SBase* sBase) { + std::string errorLog = ""; + if (sBase) + errorLog = error_log_prepareErrorMessage(user_data_getUserData(sBase, "error_log"), errorLog); + + return errorLog; + +} + +void error_log_clearErrorLog(SBase* sBase) { + if (sBase) + user_data_setUserData(sBase, "error_log", ""); +} + +const std::string error_log_prepareErrorMessage(const std::string& errorMessage, const std::string& errorLog) { + std::string preparedErrorMessage = ""; + if (!errorMessage.empty()) { + if (!errorLog.empty()) + preparedErrorMessage += "\n"; + + preparedErrorMessage += errorMessage; + } + + return preparedErrorMessage; +} + +void error_log_addErrorToLog(SBase* sBase, const std::string& errorMessage) { + if (sBase && !errorMessage.empty()) { + std::string errorLog = user_data_getUserData(sBase, "error_log"); + if (!errorLog.empty()) + errorLog += "\n"; + errorLog += errorMessage; + user_data_setUserData(sBase, "error_log", errorLog); + } +} + +const std::string error_log_createErrorMessage(const std::string& value, std::vector validValues) { + std::string errorMessage = "error: " + value + " is not a valid value. It must be one of the following: "; + for (unsigned int i = 0; i < validValues.size(); i++) { + if (i != validValues.size() - 1) { + errorMessage += validValues[i]; + errorMessage += ", "; + } else { + errorMessage += "or "; + errorMessage += validValues[i]; + } + } + + return errorMessage; +} + +} diff --git a/src/features/error_log/libsbmlnetwork_error_log.h b/src/features/error_log/libsbmlnetwork_error_log.h new file mode 100644 index 0000000..4434267 --- /dev/null +++ b/src/features/error_log/libsbmlnetwork_error_log.h @@ -0,0 +1,78 @@ +#ifndef __LIBSBMLNETWORK_ERROR_LOG_H +#define __LIBSBMLNETWORK_ERROR_LOG_H + +#ifndef SWIG +#include "sbml/SBMLTypes.h" +#include "sbml/packages/layout/common/LayoutExtensionTypes.h" +#include "sbml/packages/render/common/RenderExtensionTypes.h" +#endif + +using namespace libsbml; + +namespace LIBSBMLNETWORK_CPP_NAMESPACE { + +const std::string error_log_getErrorLog(Layout *layout); + +void error_log_clearErrorLog(Layout *layout); + +const std::string error_log_getErrorLog(GraphicalObject *graphicalObject); + +void error_log_clearErrorLog(GraphicalObject *graphicalObject); + +const std::string error_log_getErrorLog(BoundingBox *boundingBox); + +void error_log_clearErrorLog(BoundingBox *boundingBox); + +const std::string error_log_getErrorLog(Curve *curve); + +void error_log_clearErrorLog(Curve *curve); + +const std::string error_log_getErrorLog(LineSegment *lineSegment); + +void error_log_clearErrorLog(LineSegment *lineSegment); + +const std::string error_log_getErrorLog(RenderInformationBase* renderInformation); + +void error_log_clearErrorLog(RenderInformationBase* renderInformation); + +const std::string error_log_getErrorLog(ColorDefinition* colorDefinition); + +void error_log_clearErrorLog(ColorDefinition* colorDefinition); + +const std::string error_log_getErrorLog(GradientBase* gradientBase); + +void error_log_clearErrorLog(GradientBase* gradientBase); + +const std::string error_log_getErrorLog(GradientStop* gradientStop); + +void error_log_clearErrorLog(GradientStop* gradientStop); + +const std::string error_log_getErrorLog(LineEnding* lineEnding); + +void error_log_clearErrorLog(LineEnding* lineEnding); + +const std::string error_log_getErrorLog(Style* style); + +void error_log_clearErrorLog(Style* style); + +const std::string error_log_getErrorLog(RenderGroup* renderGroup); + +void error_log_clearErrorLog(RenderGroup* renderGroup); + +const std::string error_log_getErrorLog(Transformation2D* transformation2D); + +void error_log_clearErrorLog(Transformation2D* transformation2D); + +const std::string error_log_getErrorLog(SBase* sBase); + +void error_log_clearErrorLog(SBase* sBase); + +const std::string error_log_prepareErrorMessage(const std::string& errorMessage, const std::string& errorLog); + +void error_log_addErrorToLog(SBase* sBase, const std::string& errorMessage); + +const std::string error_log_createErrorMessage(const std::string& value, std::vector validValues); + +} + +#endif \ No newline at end of file diff --git a/src/features/fix_elements/libsbmlnetwork_fix_element_dimensions.cpp b/src/features/fix_elements/libsbmlnetwork_fix_element_dimensions.cpp new file mode 100644 index 0000000..e4298a0 --- /dev/null +++ b/src/features/fix_elements/libsbmlnetwork_fix_element_dimensions.cpp @@ -0,0 +1,26 @@ +#include "libsbmlnetwork_fix_element_dimensions.h" +#include "../../features/user_data/libsbmlnetwork_user_data.h" + +namespace LIBSBMLNETWORK_CPP_NAMESPACE { + +void fix_elements_fixGraphicalObjectWidth(GraphicalObject* graphicalObject) { + user_data_setUserData(graphicalObject, "fixed_width", "true"); + user_data_setUserData(graphicalObject, "width", std::to_string(graphicalObject->getBoundingBox()->width())); +} + +void fix_elements_unfixGraphicalObjectWidth(GraphicalObject* graphicalObject) { + user_data_setUserData(graphicalObject, "fixed_width", "false"); + user_data_setUserData(graphicalObject, "width", ""); +} + +void fix_elements_fixGraphicalObjectHeight(GraphicalObject* graphicalObject) { + user_data_setUserData(graphicalObject, "fixed_height", "true"); + user_data_setUserData(graphicalObject, "height", std::to_string(graphicalObject->getBoundingBox()->height())); +} + +void fix_elements_unfixGraphicalObjectHeight(GraphicalObject* graphicalObject) { + user_data_setUserData(graphicalObject, "fixed_height", "false"); + user_data_setUserData(graphicalObject, "height", ""); +} + +} diff --git a/src/features/fix_elements/libsbmlnetwork_fix_element_dimensions.h b/src/features/fix_elements/libsbmlnetwork_fix_element_dimensions.h new file mode 100644 index 0000000..bdbf4af --- /dev/null +++ b/src/features/fix_elements/libsbmlnetwork_fix_element_dimensions.h @@ -0,0 +1,23 @@ +#ifndef __LIBSBMLNETWORK_FIX_ELEMENT_DIMENSIONS_H +#define __LIBSBMLNETWORK_FIX_ELEMENT_DIMENSIONS_H + +#ifndef SWIG +#include "sbml/SBMLTypes.h" +#include "sbml/packages/layout/common/LayoutExtensionTypes.h" +#endif + +using namespace libsbml; + +namespace LIBSBMLNETWORK_CPP_NAMESPACE { + +void fix_elements_fixGraphicalObjectWidth(GraphicalObject* graphicalObject); + +void fix_elements_unfixGraphicalObjectWidth(GraphicalObject* graphicalObject); + +void fix_elements_fixGraphicalObjectHeight(GraphicalObject* graphicalObject); + +void fix_elements_unfixGraphicalObjectHeight(GraphicalObject* graphicalObject); + +} + +#endif diff --git a/src/features/fix_elements/libsbmlnetwork_fix_element_position.cpp b/src/features/fix_elements/libsbmlnetwork_fix_element_position.cpp new file mode 100644 index 0000000..97ce202 --- /dev/null +++ b/src/features/fix_elements/libsbmlnetwork_fix_element_position.cpp @@ -0,0 +1,101 @@ +#include "libsbmlnetwork_fix_element_position.h" +#include "../../libsbmlnetwork_layout.h" +#include "../../libsbmlnetwork_layout_helpers.h" +#include "../../features/fix_elements/libsbmlnetwork_fix_element_dimensions.h" +#include "../../features/user_data/libsbmlnetwork_user_data.h" + +namespace LIBSBMLNETWORK_CPP_NAMESPACE { + +void fix_elements_fixGraphicalObjectsPosition(Layout* layout, std::set > fixedPositionNodesSet, const bool resetFixedPositionElements) { + fix_elements_fixCompartmentGlyphsPosition(layout, resetFixedPositionElements); + fix_elements_fixSpeciesGlyphsPosition(layout, fixedPositionNodesSet, resetFixedPositionElements); + fix_elements_fixReactionGlyphsPosition(layout, fixedPositionNodesSet, resetFixedPositionElements); +} + +void fix_elements_fixCompartmentGlyphsPosition(Layout* layout, const bool resetFixedPositionElements) { + if (resetFixedPositionElements) { + for (unsigned int i = 0; i < layout->getNumCompartmentGlyphs(); i++) { + CompartmentGlyph* compartmentGlyph = layout->getCompartmentGlyph(i); + if (user_data_getUserData(compartmentGlyph, "fixed_position") == "true") + fix_elements_unfixGraphicalObjectPosition(compartmentGlyph); + if (user_data_getUserData(compartmentGlyph, "fixed_width") == "true") + fix_elements_unfixGraphicalObjectWidth(compartmentGlyph); + if (user_data_getUserData(compartmentGlyph, "fixed_height") == "true") + fix_elements_unfixGraphicalObjectHeight(compartmentGlyph); + } + } +} + +void fix_elements_fixSpeciesGlyphsPosition(Layout* layout, std::set > fixedPositionNodesSet, const bool resetFixedPositionElements) { + if (resetFixedPositionElements) { + for (unsigned int i = 0; i < layout->getNumSpeciesGlyphs(); i++) { + SpeciesGlyph* speciesGlyph = layout->getSpeciesGlyph(i); + if (user_data_getUserData(speciesGlyph, "fixed_position") == "true") + fix_elements_unfixGraphicalObjectPosition(speciesGlyph); + if (user_data_getUserData(speciesGlyph, "fixed_width") == "true") + fix_elements_unfixGraphicalObjectWidth(speciesGlyph); + if (user_data_getUserData(speciesGlyph, "fixed_height") == "true") + fix_elements_unfixGraphicalObjectHeight(speciesGlyph); + } + } + + for (std::set >::const_iterator fixedPositionNodeIt = fixedPositionNodesSet.cbegin(); fixedPositionNodeIt != fixedPositionNodesSet.cend(); fixedPositionNodeIt++) { + std::vector speciesGlyphs = getAssociatedSpeciesGlyphsWithSpeciesId(layout, fixedPositionNodeIt->first); + if (fixedPositionNodeIt->second < speciesGlyphs.size()) { + fix_elements_fixGraphicalObjectPosition(speciesGlyphs.at(fixedPositionNodeIt->second)); + } + } +} + +void fix_elements_fixReactionGlyphsPosition(Layout* layout, std::set > fixedPositionNodesSet, const bool resetFixedPositionElements) { + if (resetFixedPositionElements) { + for (unsigned int i = 0; i < layout->getNumReactionGlyphs(); i++) { + ReactionGlyph* reactionGlyph = layout->getReactionGlyph(i); + if (user_data_getUserData(reactionGlyph, "fixed_position") == "true") + fix_elements_unfixGraphicalObjectPosition(reactionGlyph); + if (user_data_getUserData(reactionGlyph, "fixed_width") == "true") + fix_elements_unfixGraphicalObjectWidth(reactionGlyph); + if (user_data_getUserData(reactionGlyph, "fixed_height") == "true") + fix_elements_unfixGraphicalObjectHeight(reactionGlyph); + for (unsigned int j = 0; j < reactionGlyph->getNumSpeciesReferenceGlyphs(); j++) { + SpeciesReferenceGlyph *speciesReferenceGlyph = reactionGlyph->getSpeciesReferenceGlyph(j); + if (user_data_getUserData(speciesReferenceGlyph, "fixed_position") == "true") + fix_elements_unfixGraphicalObjectPosition(speciesReferenceGlyph); + } + } + } + + for (std::set >::const_iterator fixedPositionNodeIt = fixedPositionNodesSet.cbegin(); fixedPositionNodeIt != fixedPositionNodesSet.cend(); fixedPositionNodeIt++) { + std::vector reactionGlyphs = getAssociatedReactionGlyphsWithReactionId(layout, fixedPositionNodeIt->first); + if (fixedPositionNodeIt->second < reactionGlyphs.size()) { + fix_elements_fixGraphicalObjectPosition(reactionGlyphs.at(fixedPositionNodeIt->second)); + } + } +} + +void fix_elements_fixGraphicalObjectPosition(GraphicalObject* graphicalObject) { + user_data_setUserData(graphicalObject, "fixed_position", "true"); + if (isSpeciesReferenceGlyph(graphicalObject)) + user_data_setPositionData((SpeciesReferenceGlyph*)graphicalObject); + else + user_data_setPositionData(graphicalObject); +} + +void fix_elements_unfixGraphicalObjectPosition(GraphicalObject* graphicalObject) { + user_data_setUserData(graphicalObject, "fixed_position", "false"); + if (isSpeciesReferenceGlyph(graphicalObject)) + user_data_unsetPositionData((SpeciesReferenceGlyph*)graphicalObject); + else + user_data_unsetPositionData(graphicalObject); +} + +std::vector fix_elements_getFixedPositionGraphicalObjects(std::vector graphicalObjects) { + std::vector fixedPositionGraphicalObjects; + for (unsigned int i = 0; i < graphicalObjects.size(); i++) + if (user_data_getUserData(graphicalObjects.at(i), "fixed_position") == "true") + fixedPositionGraphicalObjects.push_back(graphicalObjects.at(i)); + + return fixedPositionGraphicalObjects; +} + +} diff --git a/src/features/fix_elements/libsbmlnetwork_fix_element_position.h b/src/features/fix_elements/libsbmlnetwork_fix_element_position.h new file mode 100644 index 0000000..3314316 --- /dev/null +++ b/src/features/fix_elements/libsbmlnetwork_fix_element_position.h @@ -0,0 +1,31 @@ +#ifndef __LIBSBMLNETWORK_FIX_ELEMENTS_POSITION_H +#define __LIBSBMLNETWORK_FIX_ELEMENTS_POSITION_H + +#ifndef SWIG +#include "sbml/SBMLTypes.h" +#include "sbml/packages/layout/common/LayoutExtensionTypes.h" +#endif + +#include + +using namespace libsbml; + +namespace LIBSBMLNETWORK_CPP_NAMESPACE { + +void fix_elements_fixGraphicalObjectsPosition(Layout* layout, std::set > fixedElementNodesSet, const bool resetFixedPositionElements); + +void fix_elements_fixCompartmentGlyphsPosition(Layout* layout, const bool resetFixedPositionElements); + +void fix_elements_fixSpeciesGlyphsPosition(Layout* layout, std::set > fixedElementNodesSet, const bool resetFixedPositionElements); + +void fix_elements_fixReactionGlyphsPosition(Layout* layout, std::set > fixedElementNodesSet, const bool resetFixedPositionElements); + +void fix_elements_fixGraphicalObjectPosition(GraphicalObject* graphicalObject); + +void fix_elements_unfixGraphicalObjectPosition(GraphicalObject* graphicalObject); + +std::vector fix_elements_getFixedPositionGraphicalObjects(std::vector graphicalObjects); + +} + +#endif diff --git a/src/features/hide_elements/libsbmlnetwork_hide_species.cpp b/src/features/hide_elements/libsbmlnetwork_hide_species.cpp new file mode 100644 index 0000000..f2a9c06 --- /dev/null +++ b/src/features/hide_elements/libsbmlnetwork_hide_species.cpp @@ -0,0 +1,67 @@ +#include "libsbmlnetwork_hide_species.h" +#include "../../libsbmlnetwork_layout.h" +#include "../../libsbmlnetwork_layout_helpers.h" +#include "../../features/user_data/libsbmlnetwork_user_data.h" + +namespace LIBSBMLNETWORK_CPP_NAMESPACE { + +int hide_elements_makeSpeciesGlyphsVisible(Model* model, Layout* layout, std::set > species, bool visible) { + for (std::set >::const_iterator speciesIt = species.cbegin(); speciesIt != species.cend(); speciesIt++) { + if (hide_elements_makeSpeciesGlyphVisible(getReactionGlyph(layout, std::get<1>(*speciesIt), std::get<2>(*speciesIt)), std::get<0>(*speciesIt), visible)) + return -1; + } + + return 0; +} + +int hide_elements_makeSpeciesGlyphVisible(ReactionGlyph* reactionGlyph, const std::string speciesId, bool visible) { + if (!visible) + return hide_elements_hideSpeciesGlyph(reactionGlyph, speciesId); + else + return hide_elements_unHideSpeciesGlyph(reactionGlyph, speciesId); +} + +int hide_elements_hideSpeciesGlyph(SBase* sBase, const std::string speciesId) { + if (sBase) { + std::string hiddenSpeciesIds = user_data_getUserData(sBase, "hidden_species_ids"); + if (hiddenSpeciesIds.find(speciesId) == std::string::npos) { + if (hiddenSpeciesIds.size()) + hiddenSpeciesIds += ","; + hiddenSpeciesIds += speciesId; + if (isGraphicalObject(sBase)) + user_data_setUserData((GraphicalObject*)sBase, "hidden_species_ids", hiddenSpeciesIds); + else + user_data_setUserData(sBase, "hidden_species_ids", hiddenSpeciesIds); + } + + return 0; + } + + return -1; +} + +int hide_elements_unHideSpeciesGlyph(SBase* sBase, const std::string speciesId) { + if (sBase) { + std::string hiddenSpeciesIds = user_data_getUserData(sBase, "hidden_species_ids"); + size_t found = hiddenSpeciesIds.find(speciesId); + if (found != std::string::npos) { + hiddenSpeciesIds.erase(found, speciesId.size()); + if (hiddenSpeciesIds.back() == ',') + hiddenSpeciesIds.pop_back(); + if (isGraphicalObject(sBase)) + user_data_setUserData((GraphicalObject*)sBase, "hidden_species_ids", hiddenSpeciesIds); + else + user_data_setUserData(sBase, "hidden_species_ids", hiddenSpeciesIds); + } + + return 0; + } + + return -1; +} + +const bool hide_elements_isSpeciesGlyphHidden(Layout* layout, ReactionGlyph* reactionGlyph, const std::string speciesId) { + return user_data_getUserData(layout, "hidden_species_ids").find(speciesId) != std::string::npos || user_data_getUserData(reactionGlyph, "hidden_species_ids").find(speciesId) != std::string::npos; +} + +} diff --git a/src/features/hide_elements/libsbmlnetwork_hide_species.h b/src/features/hide_elements/libsbmlnetwork_hide_species.h new file mode 100644 index 0000000..e474fdb --- /dev/null +++ b/src/features/hide_elements/libsbmlnetwork_hide_species.h @@ -0,0 +1,26 @@ +#ifndef __LIBSBMLNETWORK_HIDE_SPECIES_H +#define __LIBSBMLNETWORK_HIDE_SPECIES_H + +#ifndef SWIG +#include "sbml/SBMLTypes.h" +#include "sbml/packages/layout/common/LayoutExtensionTypes.h" +#include "sbml/packages/render/common/RenderExtensionTypes.h" +#endif + +using namespace libsbml; + +namespace LIBSBMLNETWORK_CPP_NAMESPACE { + +int hide_elements_makeSpeciesGlyphsVisible(Model* model, Layout* layout, std::set > species, bool visible = true); + +int hide_elements_makeSpeciesGlyphVisible(ReactionGlyph* reactionGlyph, const std::string speciesId, bool visible = true); + +int hide_elements_hideSpeciesGlyph(SBase* sBase, const std::string speciesId); + +int hide_elements_unHideSpeciesGlyph(SBase* sBase, const std::string speciesId); + +const bool hide_elements_isSpeciesGlyphHidden(Layout* layout, ReactionGlyph* reactionGlyph, const std::string speciesId); + +} + +#endif diff --git a/src/features/set_layout_features/libsbmlnetwork_set_layout_features.cpp b/src/features/set_layout_features/libsbmlnetwork_set_layout_features.cpp new file mode 100644 index 0000000..ed4b3d0 --- /dev/null +++ b/src/features/set_layout_features/libsbmlnetwork_set_layout_features.cpp @@ -0,0 +1,448 @@ +#include "libsbmlnetwork_set_layout_features.h" +#include "../../libsbmlnetwork_layout.h" +#include "../../libsbmlnetwork_layout_helpers.h" +#include "../../features/autolayout/libsbmlnetwork_autolayout.h" +#include "../../features/user_data/libsbmlnetwork_user_data.h" +#include "../../features/defaults/libsbmlnetwork_defaults_layout.h" +#include "../../features/hide_elements/libsbmlnetwork_hide_species.h" +#include "../../features/fix_elements/libsbmlnetwork_fix_element_position.h" + +namespace LIBSBMLNETWORK_CPP_NAMESPACE { + +int set_layout_features_setDefaultLayoutFeatures(SBMLDocument* document, Layout* layout, const int maxNumConnectedEdges) { + if (document && layout) { + defaults_setDefaultLayoutId(layout); + defaults_setDefaultLayoutDimensions(layout); + Model* model = document->getModel(); + if (model) { + set_layout_features_clearGraphicalObjects(layout); + set_layout_features_setCompartmentGlyphs(model, layout); + set_layout_features_setReactionGlyphs(model, layout, maxNumConnectedEdges); + set_layout_features_setTextGlyphs(layout); + return 0; + } + } + + return -1; +} + +int set_layout_features_setDefaultLayoutLocations(SBMLDocument* document, Layout* layout, const int maxNumConnectedEdges, bool useNameAsTextLabel, + bool resetFixedPositionElements, const std::set > fixedPositionNodesSet) { + if (document && layout) { + defaults_setDefaultLayoutId(layout); + defaults_setDefaultLayoutDimensions(layout); + Model* model = document->getModel(); + if (model) { + fix_elements_fixGraphicalObjectsPosition(layout, fixedPositionNodesSet, resetFixedPositionElements); + std::vector> userData = user_data_getUserData(layout); + set_layout_features_clearGraphicalObjects(layout); + set_layout_features_setCompartmentGlyphs(model, layout, userData); + set_layout_features_setReactionGlyphs(model, layout, maxNumConnectedEdges, userData); + autolayout_locateGlyphs(model, layout, useNameAsTextLabel); + set_layout_features_setTextGlyphs(layout); + return 0; + } +} + +return -1; +} + +void set_layout_features_clearGraphicalObjects(Layout* layout) { + set_layout_features_clearCompartmentGlyphs(layout); + set_layout_features_clearSpeciesGlyphs(layout); + set_layout_features_clearReactionGlyphs(layout); + set_layout_features_clearTextGlyphs(layout); +} + +void set_layout_features_clearCompartmentGlyphs(Layout* layout) { + while (layout->getNumCompartmentGlyphs()) { + user_data_freeUserData(layout->getCompartmentGlyph(0)); + delete layout->removeCompartmentGlyph(0); + } +} + +void set_layout_features_clearSpeciesGlyphs(Layout* layout) { + while (layout->getNumSpeciesGlyphs()) { + user_data_freeUserData(layout->getSpeciesGlyph(0)); + delete layout->removeSpeciesGlyph(0); + } +} + +void set_layout_features_clearReactionGlyphs(Layout* layout) { + while (layout->getNumReactionGlyphs()) { + set_layout_features_clearReactionGlyphSpeciesReferenceGlyphs(layout->getReactionGlyph(0)); + user_data_freeUserData(layout->getReactionGlyph(0)); + delete layout->removeReactionGlyph(0); + } + +} + +void set_layout_features_clearReactionGlyphSpeciesReferenceGlyphs(ReactionGlyph* reactionGlyph) { + while (reactionGlyph->getNumSpeciesReferenceGlyphs()) { + user_data_freeUserData(reactionGlyph->getSpeciesReferenceGlyph(0)); + delete reactionGlyph->removeSpeciesReferenceGlyph(0); + } +} + +void set_layout_features_clearTextGlyphs(Layout* layout) { + while (layout->getNumTextGlyphs()) { + user_data_freeUserData(layout->getTextGlyph(0)); + delete layout->removeTextGlyph(0); + } +} + +void set_layout_features_clearReactionTextGlyphs(Layout* layout) { + for (unsigned int i = 0; i < layout->getNumReactionGlyphs(); i++) { + ReactionGlyph* reactionGlyph = layout->getReactionGlyph(i); + std::vector textGlyphs = getAssociatedTextGlyphsWithGraphicalObject(layout, reactionGlyph); + for (unsigned int j = 0; j < textGlyphs.size(); j++) { + user_data_freeUserData(textGlyphs.at(j)); + delete layout->removeTextGlyph(textGlyphs.at(j)->getId()); + } + } +} + +void set_layout_features_setCompartmentGlyphs(Model* model, Layout* layout, const std::vector>& userData) { + for (unsigned int i = 0; i < model->getNumCompartments(); i++) { + Compartment *compartment = model->getCompartment(i); + CompartmentGlyph *compartmentGlyph = set_layout_features_createCompartmentGlyph(layout, compartment->getId(), userData); + set_layout_features_setGraphicalObjectBoundingBox(compartmentGlyph); + } +} + +void set_layout_features_setReactionGlyphs(Model* model, Layout* layout, const int maxNumConnectedEdges, const std::vector>& userData) { + for (unsigned int i = 0; i < model->getNumReactions(); i++) { + Reaction* reaction = model->getReaction(i); + ReactionGlyph* reactionGlyph = set_layout_features_createReactionGlyph(layout, reaction->getId(), userData); + set_layout_features_setReactantGlyphs(layout, reaction, reactionGlyph, maxNumConnectedEdges, userData); + set_layout_features_setProductGlyphs(layout, reaction, reactionGlyph, maxNumConnectedEdges, userData); + set_layout_features_setModifierGlyphs(layout, reaction, reactionGlyph, maxNumConnectedEdges, userData); + set_layout_features_setEmptySpeciesReferenceGlyphs(model, layout, reactionGlyph, userData); + } +} + +void set_layout_features_setReactantGlyphs(Layout* layout, Reaction* reaction, ReactionGlyph* reactionGlyph, const int maxNumConnectedEdges, const std::vector>& userData) { + for (unsigned int i = 0; i < reaction->getNumReactants(); i++) { + SimpleSpeciesReference* speciesReference = reaction->getReactant(i); + if (!hide_elements_isSpeciesGlyphHidden(layout, reactionGlyph, speciesReference->getSpecies())) { + int stoichiometry = getStoichiometryAsInteger(speciesReference); + for (unsigned int stoichiometryIndex = 0; stoichiometryIndex < stoichiometry; stoichiometryIndex++) { + SpeciesReferenceGlyph *speciesReferenceGlyph = set_layout_features_createSpeciesReferenceGlyph(layout, reactionGlyph, speciesReference->getSpecies(), stoichiometryIndex, maxNumConnectedEdges, userData); + speciesReferenceGlyph->setRole(SPECIES_ROLE_SUBSTRATE); + } + } + } +} + +void set_layout_features_setProductGlyphs(Layout* layout, Reaction* reaction, ReactionGlyph* reactionGlyph, const int maxNumConnectedEdges, const std::vector>& userData) { + for (unsigned int i = 0; i < reaction->getNumProducts(); i++) { + SimpleSpeciesReference* speciesReference = reaction->getProduct(i); + if (!hide_elements_isSpeciesGlyphHidden(layout, reactionGlyph, speciesReference->getSpecies())) { + int stoichiometry = getStoichiometryAsInteger(speciesReference); + for (unsigned int stoichiometryIndex = 0; stoichiometryIndex < stoichiometry; stoichiometryIndex++) { + SpeciesReferenceGlyph* speciesReferenceGlyph = set_layout_features_createSpeciesReferenceGlyph(layout, reactionGlyph, speciesReference->getSpecies(), stoichiometryIndex, maxNumConnectedEdges, userData); + speciesReferenceGlyph->setRole(SPECIES_ROLE_PRODUCT); + } + } + } +} + +void set_layout_features_setModifierGlyphs(Layout* layout, Reaction* reaction, ReactionGlyph* reactionGlyph, const int maxNumConnectedEdges, const std::vector>& userData) { + for (unsigned int i = 0; i < reaction->getNumModifiers(); i++) { + SimpleSpeciesReference* speciesReference = reaction->getModifier(i); + if (!hide_elements_isSpeciesGlyphHidden(layout, reactionGlyph, speciesReference->getSpecies())) { + SpeciesReferenceGlyph* speciesReferenceGlyph = set_layout_features_createSpeciesReferenceGlyph(layout, reactionGlyph, speciesReference->getSpecies(), 0, maxNumConnectedEdges, userData); + if (speciesReference->getSBOTermID() == "SBO:0000020") + speciesReferenceGlyph->setRole(SPECIES_ROLE_INHIBITOR); + else + speciesReferenceGlyph->setRole(SPECIES_ROLE_MODIFIER); + } + } +} + +void set_layout_features_setEmptySpeciesReferenceGlyphs(Model* model, Layout* layout, ReactionGlyph* reactionGlyph, const std::vector>& userData) { + Reaction* reaction = findReactionGlyphReaction(model, reactionGlyph); + if (reaction->getNumReactants() == 0) { + SpeciesReferenceGlyph* emptyReactantGlyph = set_layout_features_createEmptySpeciesReferenceGlyph(model, layout, reactionGlyph); + emptyReactantGlyph->setRole(SPECIES_ROLE_SUBSTRATE); + user_data_setGraphicalObjectUserData(emptyReactantGlyph, userData); + } + else if (reaction->getNumProducts() == 0) { + SpeciesReferenceGlyph* emptyProductGlyph = set_layout_features_createEmptySpeciesReferenceGlyph(model, layout, reactionGlyph); + emptyProductGlyph->setRole(SPECIES_ROLE_PRODUCT); + user_data_setGraphicalObjectUserData(emptyProductGlyph, userData); + } +} + +SpeciesReferenceGlyph* set_layout_features_createEmptySpeciesReferenceGlyph(Model* model, Layout* layout, ReactionGlyph* reactionGlyph) { + SpeciesGlyph* emptySpeciesGlyph = set_layout_features_createEmptySpeciesGlyph(model, layout, reactionGlyph); + return set_layout_features_createEmptySpeciesReferenceGlyph(layout, reactionGlyph, emptySpeciesGlyph); +} + +SpeciesGlyph* set_layout_features_createEmptySpeciesGlyph(Model* model, Layout* layout, ReactionGlyph* reactionGlyph) { + SpeciesGlyph* emptySpeciesGlyph = set_layout_features_createEmptySpeciesGlyph(layout, reactionGlyph->getId()); + CompartmentGlyph* compartmentGlyph = getCompartmentGlyphOfReactionGlyph(model, layout, reactionGlyph); + if (compartmentGlyph) + user_data_setUserData(emptySpeciesGlyph, "compartment", compartmentGlyph->getCompartmentId()); + user_data_setUserData(emptySpeciesGlyph, "width", std::to_string(2* defaults_getEmptySpeciesDefaultRadius())); + user_data_setUserData(emptySpeciesGlyph, "height", std::to_string(2* defaults_getEmptySpeciesDefaultRadius())); + set_layout_features_setGraphicalObjectBoundingBox(emptySpeciesGlyph); + + return emptySpeciesGlyph; +} + +SpeciesReferenceGlyph* set_layout_features_createEmptySpeciesReferenceGlyph(Layout* layout, ReactionGlyph* reactionGlyph, SpeciesGlyph* emptySpeciesGlyph) { + SpeciesReferenceGlyph* emptySpeciesReferenceGlyph = layout->createSpeciesReferenceGlyph(); + emptySpeciesReferenceGlyph->setId(reactionGlyph->getId() + "_EmptySpeciesReferenceGlyph"); + emptySpeciesReferenceGlyph->setSpeciesGlyphId(emptySpeciesGlyph->getId()); + set_layout_features_setSpeciesReferenceGlyphCurve(emptySpeciesReferenceGlyph); + + return emptySpeciesReferenceGlyph; +} + +SpeciesGlyph* set_layout_features_getSpeciesGlyph(Layout* layout, const std::string& speciesId, const int maxNumConnectedEdges, const std::vector>& userData) { + std::vector speciesGlyphs = getAssociatedSpeciesGlyphsWithSpeciesId(layout, speciesId); + if (speciesGlyphs.size()) { + if (set_layout_features_getConnectedSpeciesGlyphReferences(layout, speciesGlyphs.back()).size() >= maxNumConnectedEdges) + return set_layout_features_createSpeciesGlyph(layout, speciesId, userData); + + return speciesGlyphs.back(); + } + + return set_layout_features_createSpeciesGlyph(layout, speciesId, userData); +} + +void set_layout_features_setTextGlyphs(Layout* layout) { + set_layout_features_setCompartmentTextGlyphs(layout); + set_layout_features_setSpeciesTextGlyphs(layout); + set_layout_features_setReactionTextGlyphs(layout); +} + +void set_layout_features_setCompartmentTextGlyphs(Layout* layout) { + for (unsigned int i = 0; i < layout->getNumCompartmentGlyphs(); i++) { + TextGlyph* textGlyph = createAssociatedTextGlyph(layout, layout->getCompartmentGlyph(i)); + setTextGlyphBoundingBox(textGlyph, layout->getCompartmentGlyph(i)); + } +} + +void set_layout_features_setSpeciesTextGlyphs(Layout* layout) { + for (unsigned int i = 0; i < layout->getNumSpeciesGlyphs(); i++) { + TextGlyph* textGlyph = createAssociatedTextGlyph(layout, layout->getSpeciesGlyph(i)); + setTextGlyphBoundingBox(textGlyph, layout->getSpeciesGlyph(i)); + } +} + +void set_layout_features_setReactionTextGlyphs(Layout* layout) { + for (unsigned int i = 0; i < layout->getNumReactionGlyphs(); i++) { + double padding = 5.0; + TextGlyph* textGlyph = createAssociatedTextGlyph(layout, layout->getReactionGlyph(i)); + setTextGlyphBoundingBox(textGlyph, layout->getReactionGlyph(i), padding); + } +} + +CompartmentGlyph* set_layout_features_createCompartmentGlyph(Layout* layout, const std::string& compartmentId, const std::vector>& userData) { + CompartmentGlyph* compartmentGlyph = layout->createCompartmentGlyph(); + compartmentGlyph->setId(set_layout_features_getCompartmentGlyphId(layout, compartmentId)); + compartmentGlyph->setCompartmentId(compartmentId); + set_layout_features_setGraphicalObjectBoundingBox(compartmentGlyph); + user_data_setGraphicalObjectUserData(compartmentGlyph, userData); + + return compartmentGlyph; +} + +SpeciesGlyph* set_layout_features_createSpeciesGlyph(Layout* layout, const std::string& speciesId, const std::vector>& userData) { + SpeciesGlyph *speciesGlyph = layout->createSpeciesGlyph(); + speciesGlyph->setId(set_layout_features_getSpeciesGlyphId(layout, speciesId)); + speciesGlyph->setSpeciesId(speciesId); + set_layout_features_setGraphicalObjectBoundingBox(speciesGlyph); + user_data_setGraphicalObjectUserData(speciesGlyph, userData); + + return speciesGlyph; +} + +SpeciesGlyph* set_layout_features_createEmptySpeciesGlyph(Layout* layout, const std::string& reactionGlyphId) { + SpeciesGlyph *speciesGlyph = layout->createSpeciesGlyph(); + speciesGlyph->setId(reactionGlyphId + "_EmptySpeciesGlyph"); + set_layout_features_setGraphicalObjectBoundingBox(speciesGlyph); + + return speciesGlyph; +} + +ReactionGlyph* set_layout_features_createReactionGlyph(Layout* layout, const std::string& reactionId, const std::vector>& userData) { + ReactionGlyph* reactionGlyph = layout->createReactionGlyph(); + reactionGlyph->setId(set_layout_features_getReactionGlyphId(layout, reactionId)); + reactionGlyph->setReactionId(reactionId); + setReactionGlyphCurve(reactionGlyph); + user_data_setGraphicalObjectUserData(reactionGlyph, userData); + + return reactionGlyph; +} + +SpeciesReferenceGlyph* set_layout_features_createSpeciesReferenceGlyph(Layout* layout, ReactionGlyph* reactionGlyph, const std::string& speciesId, unsigned int stoichiometryIndex, const int maxNumConnectedEdges, const std::vector>& userData) { + SpeciesReferenceGlyph* speciesReferenceGlyph = reactionGlyph->createSpeciesReferenceGlyph(); + SpeciesGlyph* speciesGlyph = set_layout_features_getSpeciesGlyph(layout, speciesId, maxNumConnectedEdges, userData); + speciesReferenceGlyph->setId(set_layout_features_getSpeciesReferenceGlyphId(reactionGlyph, speciesGlyph->getId(), stoichiometryIndex)); + speciesReferenceGlyph->setSpeciesGlyphId(speciesGlyph->getId()); + set_layout_features_setSpeciesReferenceGlyphCurve(speciesReferenceGlyph); + user_data_setGraphicalObjectUserData(speciesReferenceGlyph, userData); + + return speciesReferenceGlyph; +} + +SpeciesReferenceGlyph* set_layout_features_createSpeciesReferenceGlyph(ReactionGlyph* reactionGlyph, const std::string& speciesGlyphId, unsigned int stoichiometryIndex) { + SpeciesReferenceGlyph* speciesReferenceGlyph = reactionGlyph->createSpeciesReferenceGlyph(); + speciesReferenceGlyph->setId(set_layout_features_getSpeciesReferenceGlyphId(reactionGlyph, speciesGlyphId, stoichiometryIndex)); + speciesReferenceGlyph->setSpeciesGlyphId(speciesGlyphId); + + return speciesReferenceGlyph; +} + +std::vector set_layout_features_getConnectedSpeciesGlyphReferences(Layout* layout, SpeciesGlyph* speciesGlyph) { + std::vector speciesGlyphReferences; + for (unsigned int i = 0; i < layout->getNumReactionGlyphs(); i++) { + ReactionGlyph* reactionGlyph = layout->getReactionGlyph(i); + for (unsigned int j = 0; j < reactionGlyph->getNumSpeciesReferenceGlyphs(); j++) { + SpeciesReferenceGlyph* speciesReferenceGlyph = reactionGlyph->getSpeciesReferenceGlyph(j); + if (speciesReferenceGlyph->getSpeciesGlyphId() == speciesGlyph->getId()) + speciesGlyphReferences.push_back(speciesReferenceGlyph); + } + } + + return speciesGlyphReferences; +} + +const std::string set_layout_features_getCompartmentGlyphId(Layout* layout, const std::string compartmentId) { + std::string compartmentGlyphId = ""; + int compartmentGlyphIndex = 1; + std::vector compartmentGlyphs = getAssociatedCompartmentGlyphsWithCompartmentId(layout, compartmentId); + while (true) { + compartmentGlyphId = compartmentId + "_Glyph_" + std::to_string(compartmentGlyphIndex++); + bool isUniqueId = true; + for (unsigned int i = 0; i < compartmentGlyphs.size(); i++) { + if (compartmentGlyphId == compartmentGlyphs.at(i)->getId()) { + isUniqueId = false; + break; + } + } + if (isUniqueId) + break; + } + + return compartmentGlyphId; +} + +const std::string set_layout_features_getSpeciesGlyphId(Layout* layout, const std::string speciesId) { + std::string speciesGlyphId = ""; + int speciesGlyphIndex = 1; + std::vector speciesGlyphs = getAssociatedSpeciesGlyphsWithSpeciesId(layout, speciesId); + while (true) { + speciesGlyphId = speciesId + "_Glyph_" + std::to_string(speciesGlyphIndex++); + bool isUniqueId = true; + for (unsigned int i = 0; i < speciesGlyphs.size(); i++) { + if (speciesGlyphId == speciesGlyphs.at(i)->getId()) { + isUniqueId = false; + break; + } + } + if (isUniqueId) + break; + } + + return speciesGlyphId; +} + +const std::string set_layout_features_getReactionGlyphId(Layout* layout, const std::string reactionId) { + std::string reactionGlyphId = ""; + int reactionGlyphIndex = 1; + std::vector reactionGlyphs = getAssociatedReactionGlyphsWithReactionId(layout, reactionId); + while (true) { + reactionGlyphId = reactionId + "_Glyph_" + std::to_string(reactionGlyphIndex++); + bool isUniqueId = true; + for (unsigned int i = 0; i < reactionGlyphs.size(); i++) { + if (reactionGlyphId == reactionGlyphs.at(i)->getId()) { + isUniqueId = false; + break; + } + } + if (isUniqueId) + break; + } + + return reactionGlyphId; +} + +const std::string set_layout_features_getSpeciesReferenceGlyphId(ReactionGlyph* reactionGlyph, const std::string speciesGlyphId, unsigned int stoichiometryIndex) { + std::string speciesReferenceGlyphId = ""; + int speciesReferenceGlyphIndex = 1; + std::vector speciesReferenceGlyphs = getSpeciesReferenceGlyphs(reactionGlyph); + std::string stoichiometryPhrase = "_Stoichiometry_" + std::to_string(stoichiometryIndex + 1); + while (true) { + speciesReferenceGlyphId = speciesGlyphId + "_" + reactionGlyph->getId() + stoichiometryPhrase + "_Glyph_" + std::to_string(speciesReferenceGlyphIndex++); + bool isUniqueId = true; + for (unsigned int i = 0; i < speciesReferenceGlyphs.size(); i++) { + if (speciesReferenceGlyphId == speciesReferenceGlyphs.at(i)->getId()) { + isUniqueId = false; + break; + } + } + if (isUniqueId) + break; + } + + return speciesReferenceGlyphId; +} + +void set_layout_features_setGraphicalObjectBoundingBox(GraphicalObject* graphicalObject) { + if (!graphicalObject->getBoundingBox()->isSetId()) + graphicalObject->getBoundingBox()->setId(graphicalObject->getId() + "_bb"); +} + +void set_layout_features_setSpeciesReferenceGlyphCurve(SpeciesReferenceGlyph* speciesReferenceGlyph, SpeciesReferenceGlyph* referenceSpeciesReferenceGlyph) { + if (referenceSpeciesReferenceGlyph->isSetCurve()) { + Curve* referenceCurve = referenceSpeciesReferenceGlyph->getCurve(); + Curve* curve = speciesReferenceGlyph->getCurve(); + for (unsigned int i = 0; i < referenceCurve->getNumCurveSegments(); i++) + set_layout_features_addCurveSegment(curve, referenceCurve->getCurveSegment(i), defaults_getAliasReactionGlyphPadding()); + } +} + +void set_layout_features_setSpeciesReferenceGlyphCurve(SpeciesReferenceGlyph* speciesReferenceGlyph) { + if (!speciesReferenceGlyph->isSetCurve()) + set_layout_features_setCurveCubicBezier(speciesReferenceGlyph->getCurve()); +} + +void set_layout_features_addCurveSegment(Curve* curve, LineSegment* referenceLineSegment, const double& padding) { + if (isCubicBezier(referenceLineSegment)) { + CubicBezier* referenceCubicBezier = static_cast(referenceLineSegment); + CubicBezier* cubicBezier = curve->createCubicBezier(); + cubicBezier->getStart()->setX(referenceCubicBezier->getStart()->x() + padding); + cubicBezier->getStart()->setY(referenceCubicBezier->getStart()->y() + padding); + cubicBezier->getBasePoint1()->setX(referenceCubicBezier->getBasePoint1()->x() + padding); + cubicBezier->getBasePoint1()->setY(referenceCubicBezier->getBasePoint1()->y() + padding); + cubicBezier->getBasePoint2()->setX(referenceCubicBezier->getBasePoint2()->x() + padding); + cubicBezier->getBasePoint2()->setY(referenceCubicBezier->getBasePoint2()->y() + padding); + cubicBezier->getEnd()->setX(referenceCubicBezier->getEnd()->x() + padding); + cubicBezier->getEnd()->setY(referenceCubicBezier->getEnd()->y() + padding); + } + else { + LineSegment* lineSegment = curve->createLineSegment(); + lineSegment->getStart()->setX(referenceLineSegment->getStart()->x() + padding); + lineSegment->getStart()->setY(referenceLineSegment->getStart()->y() + padding); + lineSegment->getEnd()->setX(referenceLineSegment->getEnd()->x() + padding); + lineSegment->getEnd()->setY(referenceLineSegment->getEnd()->y() + padding); + } +} + +void set_layout_features_setCurveCubicBezier(Curve* curve, const double& x, const double& y) { + CubicBezier* cubicBezier = curve->createCubicBezier(); + cubicBezier->getStart()->setX(x); + cubicBezier->getStart()->setY(y); + cubicBezier->getBasePoint1()->setX(x); + cubicBezier->getBasePoint1()->setY(y); + cubicBezier->getBasePoint2()->setX(x); + cubicBezier->getBasePoint2()->setY(y); + cubicBezier->getEnd()->setX(x); + cubicBezier->getEnd()->setY(y); +} + +} diff --git a/src/features/set_layout_features/libsbmlnetwork_set_layout_features.h b/src/features/set_layout_features/libsbmlnetwork_set_layout_features.h new file mode 100644 index 0000000..8bcd5a4 --- /dev/null +++ b/src/features/set_layout_features/libsbmlnetwork_set_layout_features.h @@ -0,0 +1,100 @@ +#ifndef __LIBSBMLNETWORK_SET_LAYOUT_FEATURES_H +#define __LIBSBMLNETWORK_SET_LAYOUT_FEATURES_H + +#ifndef SWIG +#include "sbml/SBMLTypes.h" +#include "sbml/packages/layout/common/LayoutExtensionTypes.h" +#endif + +#include + +using namespace libsbml; + +namespace LIBSBMLNETWORK_CPP_NAMESPACE { + +int set_layout_features_setDefaultLayoutFeatures(SBMLDocument* document, Layout* layout, const int maxNumConnectedEdges); + +int set_layout_features_setDefaultLayoutLocations(SBMLDocument* document, Layout* layout, const int maxNumConnectedEdges, bool useNameAsTextLabel, + bool resetFixedPositionElements, const std::set > fixedPositionNodesSet); + +void set_layout_features_clearGraphicalObjects(Layout* layout); + +void set_layout_features_clearCompartmentGlyphs(Layout* layout); + +void set_layout_features_clearSpeciesGlyphs(Layout* layout); + +void set_layout_features_clearReactionGlyphs(Layout* layout); + +void set_layout_features_clearReactionGlyphSpeciesReferenceGlyphs(ReactionGlyph* reactionGlyph); + +void set_layout_features_setCompartmentGlyphs(Model* model, Layout* layout, const std::vector>& userData = {}); + +void set_layout_features_setReactionGlyphs(Model* model, Layout* layout, const int maxNumConnectedEdges, const std::vector>& userData = {}); + +void set_layout_features_setReactantGlyphs(Layout* layout, Reaction* reaction, ReactionGlyph* reactionGlyph, const int maxNumConnectedEdges, const std::vector>& userData); + +void set_layout_features_setProductGlyphs(Layout* layout, Reaction* reaction, ReactionGlyph* reactionGlyph, const int maxNumConnectedEdges, const std::vector>& userData); + +void set_layout_features_setModifierGlyphs(Layout* layout, Reaction* reaction, ReactionGlyph* reactionGlyph, const int maxNumConnectedEdges, const std::vector>& userData); + +void set_layout_features_setEmptySpeciesReferenceGlyphs(Model* model, Layout* layout, ReactionGlyph* reactionGlyph, const std::vector>& userData = {}); + +SpeciesReferenceGlyph* set_layout_features_createEmptySpeciesReferenceGlyph(Model* model, Layout* layout, ReactionGlyph* reactionGlyph); + +SpeciesGlyph* set_layout_features_createEmptySpeciesGlyph(Model* model, Layout* layout, ReactionGlyph* reactionGlyph); + +SpeciesGlyph* set_layout_features_createEmptySpeciesGlyph(ReactionGlyph* reactionGlyph); + +SpeciesReferenceGlyph* set_layout_features_createEmptySpeciesReferenceGlyph(Layout* layout, ReactionGlyph* reactionGlyph, SpeciesGlyph* EmptySpeciesGlyph); + +SpeciesGlyph* set_layout_features_getSpeciesGlyph(Layout* layout, const std::string& speciesId, const int maxNumConnectedEdges, const std::vector>& userData); + +void set_layout_features_setTextGlyphs(Layout* layout); + +void set_layout_features_clearTextGlyphs(Layout* layout); + +void set_layout_features_clearReactionTextGlyphs(Layout* layout); + +void set_layout_features_setCompartmentTextGlyphs(Layout* layout); + +void set_layout_features_setSpeciesTextGlyphs(Layout* layout); + +void set_layout_features_setReactionTextGlyphs(Layout* layout); + +CompartmentGlyph* set_layout_features_createCompartmentGlyph(Layout* layout, const std::string& compartmentId, const std::vector>& userData = {}); + +SpeciesGlyph* set_layout_features_createSpeciesGlyph(Layout* layout, const std::string& speciesId, const std::vector>& userData = {}); + +SpeciesGlyph* set_layout_features_createEmptySpeciesGlyph(Layout* layout, const std::string& reactionGlyphId); + +ReactionGlyph* set_layout_features_createReactionGlyph(Layout* layout, const std::string& reactionId, const std::vector>& userData = {}); + +SpeciesReferenceGlyph* set_layout_features_createSpeciesReferenceGlyph(Layout* layout, ReactionGlyph* reactionGlyph, const std::string& speciesId, unsigned int stoichiometryIndex, const int maxNumConnectedEdges, const std::vector>& userData = {}); + +SpeciesReferenceGlyph* set_layout_features_createSpeciesReferenceGlyph(ReactionGlyph* reactionGlyph, const std::string& speciesId, unsigned int stoichiometryIndex); + +std::vector set_layout_features_getConnectedSpeciesGlyphReferences(Layout* layout, SpeciesGlyph* speciesGlyph); + +const std::string set_layout_features_getTextGlyphUniqueId(Layout* layout, GraphicalObject* graphicalObject); + +const std::string set_layout_features_getCompartmentGlyphId(Layout* layout, const std::string compartmentId); + +const std::string set_layout_features_getSpeciesGlyphId(Layout* layout, const std::string speciesId); + +const std::string set_layout_features_getReactionGlyphId(Layout* layout, const std::string reactionId); + +const std::string set_layout_features_getSpeciesReferenceGlyphId(ReactionGlyph* reactionGlyph, const std::string speciesGlyphId, unsigned int stoichiometryIndex = 0); + +void set_layout_features_setGraphicalObjectBoundingBox(GraphicalObject* graphicalObject); + +void set_layout_features_setSpeciesReferenceGlyphCurve(SpeciesReferenceGlyph* speciesReferenceGlyph, SpeciesReferenceGlyph* referenceSpeciesReferenceGlyph); + +void set_layout_features_setSpeciesReferenceGlyphCurve(SpeciesReferenceGlyph* speciesReferenceGlyph); + +void set_layout_features_addCurveSegment(Curve* curve, LineSegment* referenceLineSegment, const double& padding); + +void set_layout_features_setCurveCubicBezier(Curve* curve, const double& x = 0.0, const double& y = 0.0); + +} + +#endif diff --git a/src/styles/libsbmlnetwork_styles.cpp b/src/features/styles/libsbmlnetwork_styles.cpp similarity index 99% rename from src/styles/libsbmlnetwork_styles.cpp rename to src/features/styles/libsbmlnetwork_styles.cpp index d068486..fca0dfb 100644 --- a/src/styles/libsbmlnetwork_styles.cpp +++ b/src/features/styles/libsbmlnetwork_styles.cpp @@ -1,5 +1,5 @@ #include "libsbmlnetwork_styles.h" -#include "../libsbmlnetwork_common.h" +#include "../../libsbmlnetwork_common.h" #include diff --git a/src/styles/libsbmlnetwork_styles.h b/src/features/styles/libsbmlnetwork_styles.h similarity index 100% rename from src/styles/libsbmlnetwork_styles.h rename to src/features/styles/libsbmlnetwork_styles.h diff --git a/src/features/update_curves/libsbmlnetwork_update_curves.cpp b/src/features/update_curves/libsbmlnetwork_update_curves.cpp new file mode 100644 index 0000000..ffc0730 --- /dev/null +++ b/src/features/update_curves/libsbmlnetwork_update_curves.cpp @@ -0,0 +1,21 @@ +#include "libsbmlnetwork_update_curves.h" +#include "../../features/set_layout_features/libsbmlnetwork_set_layout_features.h" +#include "../../features/autolayout/libsbmlnetwork_autolayout.h" + +namespace LIBSBMLNETWORK_CPP_NAMESPACE { + + int update_curves_updateLayoutCurves(SBMLDocument* document, Layout* layout) { + if (document && layout) { + Model* model = document->getModel(); + if (model) { + set_layout_features_clearReactionTextGlyphs(layout); + autolayout_locateReactions(model, layout, true); + set_layout_features_setReactionTextGlyphs(layout); + return 0; + } + } + + return -1; + } + +} diff --git a/src/features/update_curves/libsbmlnetwork_update_curves.h b/src/features/update_curves/libsbmlnetwork_update_curves.h new file mode 100644 index 0000000..f63a31f --- /dev/null +++ b/src/features/update_curves/libsbmlnetwork_update_curves.h @@ -0,0 +1,16 @@ +#ifndef __LIBSBMLNETWORK_UPDATE_CURVES_H +#define __LIBSBMLNETWORK_UPDATE_CURVES_H + +#ifndef SWIG +#include "sbml/SBMLTypes.h" +#include "sbml/packages/layout/common/LayoutExtensionTypes.h" +#endif + +using namespace libsbml; + +namespace LIBSBMLNETWORK_CPP_NAMESPACE { + + int update_curves_updateLayoutCurves(SBMLDocument* document, Layout* layout); +} + +#endif diff --git a/src/features/user_data/libsbmlnetwork_user_data.cpp b/src/features/user_data/libsbmlnetwork_user_data.cpp new file mode 100644 index 0000000..87d55e3 --- /dev/null +++ b/src/features/user_data/libsbmlnetwork_user_data.cpp @@ -0,0 +1,222 @@ +#include "libsbmlnetwork_user_data.h" +#include "../../libsbmlnetwork_sbmldocument_layout.h" +#include "../../libsbmlnetwork_layout.h" +#include "../../libsbmlnetwork_layout_helpers.h" + +namespace LIBSBMLNETWORK_CPP_NAMESPACE { + +void user_data_freeUserData(SBMLDocument* document) { + if (document) { + ListOfLayouts* listOfLayouts = getListOfLayouts(document); + user_data_freeUserData(listOfLayouts); + const int numLayouts = getNumLayouts(document); + for (int i = 0; i < numLayouts; i++) + user_data_freeUserData(getLayout(document, i)); + } +} + +void user_data_freeUserData(Layout* layout) { + if (layout->isSetUserData()) { + auto userData = (std::map*)layout->getUserData(); + if (userData) { + delete userData; + } + } + user_data_freeUserData(layout->getDimensions()); + for (unsigned int i = 0; i < layout->getNumCompartmentGlyphs(); i++) { + CompartmentGlyph* compartmentGlyph = layout->getCompartmentGlyph(i); + user_data_freeUserData(compartmentGlyph); + user_data_freeUserData(compartmentGlyph->getBoundingBox()); + } + for (unsigned int i = 0; i < layout->getNumSpeciesGlyphs(); i++) { + SpeciesGlyph* speciesGlyph = layout->getSpeciesGlyph(i); + user_data_freeUserData(speciesGlyph); + user_data_freeUserData(speciesGlyph->getBoundingBox()); + } + for (unsigned int i = 0; i < layout->getNumReactionGlyphs(); i++) { + ReactionGlyph* reactionGlyph = layout->getReactionGlyph(i); + user_data_freeUserData(reactionGlyph); + user_data_freeUserData(reactionGlyph->getBoundingBox()); + user_data_freeUserData(reactionGlyph->getCurve()); + for (unsigned int j = 0; j < reactionGlyph->getNumSpeciesReferenceGlyphs(); j++) { + SpeciesReferenceGlyph* speciesReferenceGlyph = reactionGlyph->getSpeciesReferenceGlyph(j); + user_data_freeUserData(speciesReferenceGlyph); + user_data_freeUserData(speciesReferenceGlyph->getCurve()); + } + } +} + +std::vector> user_data_getUserData(Layout* layout) { + std::vector> userData; + for (unsigned int i = 0; i < layout->getNumCompartmentGlyphs(); i++) { + auto compartmentGlyphUserData = layout->getCompartmentGlyph(i)->getUserData(); + if (compartmentGlyphUserData) + userData.push_back(*(std::map*)compartmentGlyphUserData); + } + for (unsigned int i = 0; i < layout->getNumSpeciesGlyphs(); i++) { + auto speciesGlyphUserData = layout->getSpeciesGlyph(i)->getUserData(); + if (speciesGlyphUserData) + userData.push_back(*(std::map*)speciesGlyphUserData); + } + for (unsigned int i = 0; i < layout->getNumReactionGlyphs(); i++) { + auto reactionGlyphUserData = layout->getReactionGlyph(i)->getUserData(); + if (reactionGlyphUserData) + userData.push_back(*(std::map*)reactionGlyphUserData); + for (unsigned int j = 0; j < layout->getReactionGlyph(i)->getNumSpeciesReferenceGlyphs(); j++) { + auto speciesReferenceGlyphUserData = layout->getReactionGlyph(i)->getSpeciesReferenceGlyph(j)->getUserData(); + if (speciesReferenceGlyphUserData) + userData.push_back(*(std::map*)speciesReferenceGlyphUserData); + } + } + + return userData; +} + +void user_data_setUserData(GraphicalObject* graphicalObject, const std::string& key, const std::string& value) { + if (!graphicalObject->isSetUserData()) { + graphicalObject->setUserData(new std::map()); + user_data_setUserData(graphicalObject, "id", graphicalObject->getId()); + user_data_setUserData(graphicalObject, "entity_id", getEntityId(graphicalObject)); + } + auto userData = (std::map*)graphicalObject->getUserData(); + (*userData)[key] = value; +} + +void user_data_setPositionData(GraphicalObject* graphicalObject) { + user_data_setUserData(graphicalObject, "x", std::to_string(getPositionX(graphicalObject))); + user_data_setUserData(graphicalObject, "y", std::to_string(getPositionY(graphicalObject))); +} + +void user_data_unsetPositionData(GraphicalObject* graphicalObject) { + user_data_setUserData(graphicalObject, "x", ""); + user_data_setUserData(graphicalObject, "y", ""); +} + +void user_data_setPositionData(SpeciesReferenceGlyph* speciesReferenceGlyph) { + if (speciesReferenceGlyph) { + Curve* curve = getCurve(speciesReferenceGlyph); + for (unsigned int i = 0; i < getNumCurveSegments(curve); i++) { + user_data_setUserData(speciesReferenceGlyph, std::to_string(i) + ":start_x", std::to_string(getCurveSegmentStartPointX(curve, i))); + user_data_setUserData(speciesReferenceGlyph, std::to_string(i) + ":start_y", std::to_string(getCurveSegmentStartPointY(curve, i))); + user_data_setUserData(speciesReferenceGlyph, std::to_string(i) + ":end_x", std::to_string(getCurveSegmentEndPointX(curve, i))); + user_data_setUserData(speciesReferenceGlyph, std::to_string(i) + ":end_y", std::to_string(getCurveSegmentEndPointY(curve, i))); + if (isCubicBezier(curve, i)) { + user_data_setUserData(speciesReferenceGlyph, std::to_string(i) + ":b1_x", std::to_string(getCurveSegmentBasePoint1X(curve, i))); + user_data_setUserData(speciesReferenceGlyph, std::to_string(i) + ":b1_y", std::to_string(getCurveSegmentBasePoint1Y(curve, i))); + user_data_setUserData(speciesReferenceGlyph, std::to_string(i) + ":b2_x", std::to_string(getCurveSegmentBasePoint2X(curve, i))); + user_data_setUserData(speciesReferenceGlyph, std::to_string(i) + ":b2_y", std::to_string(getCurveSegmentBasePoint2Y(curve, i))); + } + } + } +} + +void user_data_unsetPositionData(SpeciesReferenceGlyph* speciesReferenceGlyph) { + if (speciesReferenceGlyph) { + Curve* curve = getCurve(speciesReferenceGlyph); + for (unsigned int i = 0; i < getNumCurveSegments(curve); i++) { + user_data_setUserData(curve, std::to_string(i) + ":start_x", ""); + user_data_setUserData(curve, std::to_string(i) + ":start_y", ""); + user_data_setUserData(curve, std::to_string(i) + ":end_x", ""); + user_data_setUserData(curve, std::to_string(i) + ":end_y", ""); + user_data_setUserData(curve, std::to_string(i) + ":b1_x", ""); + user_data_setUserData(curve, std::to_string(i) + ":b1_y", ""); + user_data_setUserData(curve, std::to_string(i) + ":b2_x", ""); + user_data_setUserData(curve, std::to_string(i) + ":b2_y", ""); + } + } +} + +void user_data_setGraphicalObjectUserData(GraphicalObject* graphicalObject, const std::vector>& userData) { + for (unsigned int i = 0; i < userData.size(); i++) { + if (userData.at(i).find("id") != userData.at(i).end() && userData.at(i).at("id") == graphicalObject->getId()) { + for (auto it = userData.at(i).begin(); it != userData.at(i).end(); it++) + user_data_setUserData(graphicalObject, it->first, it->second); + break; + } + } +} + +void user_data_freeUserData(RenderInformationBase* renderInformation) { + for (unsigned int i = 0; i < renderInformation->getNumColorDefinitions(); i++) + user_data_freeUserData(renderInformation->getColorDefinition(i)); + for (unsigned int i = 0; i < renderInformation->getNumGradientDefinitions(); i++) { + GradientBase* gradientBase = renderInformation->getGradientDefinition(i); + user_data_freeUserData(gradientBase); + for (unsigned int j = 0; j < gradientBase->getNumGradientStops(); j++) + user_data_freeUserData(gradientBase->getGradientStop(j)); + } + for (unsigned int i = 0; i < renderInformation->getNumLineEndings(); i++) + user_data_freeUserData(renderInformation->getLineEnding(i)); + if (renderInformation->isGlobalRenderInformation()) { + for (unsigned int i = 0; i < ((GlobalRenderInformation*)renderInformation)->getNumGlobalStyles(); i++) + user_data_freeUserData(((GlobalRenderInformation*)renderInformation)->getGlobalStyle(i)); + } + else if (renderInformation->isLocalRenderInformation()) { + for (unsigned int i = 0; i < ((LocalRenderInformation*)renderInformation)->getNumLocalStyles(); i++) + user_data_freeUserData(((LocalRenderInformation*)renderInformation)->getLocalStyle(i)); + } +} + +std::vector> user_data_getUserData(RenderInformationBase* renderInformation) { + std::vector> userData; + for (unsigned int i = 0; i < renderInformation->getNumColorDefinitions(); i++) { + auto colorDefinitionUserData = renderInformation->getColorDefinition(i)->getUserData(); + if (colorDefinitionUserData) + userData.push_back(*(std::map*)colorDefinitionUserData); + } + for (unsigned int i = 0; i < renderInformation->getNumGradientDefinitions(); i++) { + auto gradientDefinitionUserData = renderInformation->getGradientDefinition(i)->getUserData(); + if (gradientDefinitionUserData) + userData.push_back(*(std::map*)gradientDefinitionUserData); + } + for (unsigned int i = 0; i < renderInformation->getNumLineEndings(); i++) { + auto lineEndingUserData = renderInformation->getLineEnding(i)->getUserData(); + if (lineEndingUserData) + userData.push_back(*(std::map*)lineEndingUserData); + } + if (renderInformation->isGlobalRenderInformation()) { + for (unsigned int i = 0; i < ((GlobalRenderInformation*)renderInformation)->getNumGlobalStyles(); i++) { + auto globalStyleUserData = ((GlobalRenderInformation*)renderInformation)->getGlobalStyle(i)->getUserData(); + if (globalStyleUserData) + userData.push_back(*(std::map*)globalStyleUserData); + } + } + else if (renderInformation->isLocalRenderInformation()) { + for (unsigned int i = 0; i < ((LocalRenderInformation*)renderInformation)->getNumLocalStyles(); i++) { + auto localStyleUserData = ((LocalRenderInformation*)renderInformation)->getLocalStyle(i)->getUserData(); + if (localStyleUserData) + userData.push_back(*(std::map*)localStyleUserData); + } + } + + return userData; +} + +const std::string user_data_getUserData(SBase* sBase, const std::string& key) { + if (sBase->isSetUserData()) { + auto userData = (std::map*)sBase->getUserData(); + if (userData->find(key) != userData->end()) + return (*userData)[key]; + } + + return ""; +} + +void user_data_setUserData(SBase* sBase, const std::string& key, const std::string& value) { + if (!sBase->isSetUserData()) + sBase->setUserData(new std::map()); + auto userData = (std::map*)sBase->getUserData(); + (*userData)[key] = value; +} + +void user_data_freeUserData(SBase* sBase) { + if (sBase) { + if (sBase->isSetUserData()) { + auto userData = (std::map*)sBase->getUserData(); + delete userData; + sBase->unsetUserData(); + } + } +} + +} diff --git a/src/features/user_data/libsbmlnetwork_user_data.h b/src/features/user_data/libsbmlnetwork_user_data.h new file mode 100644 index 0000000..966fd9f --- /dev/null +++ b/src/features/user_data/libsbmlnetwork_user_data.h @@ -0,0 +1,44 @@ +#ifndef __LIBSBMLNETWORK_USER_DATA_H +#define __LIBSBMLNETWORK_USER_DATA_H + +#ifndef SWIG +#include "sbml/SBMLTypes.h" +#include "sbml/packages/layout/common/LayoutExtensionTypes.h" +#include "sbml/packages/render/common/RenderExtensionTypes.h" +#endif + +using namespace libsbml; + +namespace LIBSBMLNETWORK_CPP_NAMESPACE { + +void freeUserData(Layout* layout); + +std::vector> user_data_getUserData(Layout* layout); + +void user_data_setUserData(GraphicalObject* graphicalObject, const std::string& key, const std::string& value); + +void user_data_setPositionData(GraphicalObject* graphicalObject); + +void user_data_unsetPositionData(GraphicalObject* graphicalObject); + +void user_data_setPositionData(SpeciesReferenceGlyph* speciesReferenceGlyph); + +void user_data_unsetPositionData(SpeciesReferenceGlyph* speciesReferenceGlyph); + +void user_data_setGraphicalObjectUserData(GraphicalObject* graphicalObject, const std::vector>& userData); + +void user_data_freeUserData(RenderInformationBase* renderInformation); + +std::vector> user_data_getUserData(RenderInformationBase* renderInformationBase); + +const std::string user_data_getUserData(SBase* sbase, const std::string& key); + +void user_data_setUserData(SBase* sBase, const std::string& key, const std::string& value); + +void user_data_freeUserData(SBMLDocument* document); + +void user_data_freeUserData(SBase* sbase); + +} + +#endif diff --git a/src/libsbmlnetwork_common.cpp b/src/libsbmlnetwork_common.cpp index 6d9550e..19c88ae 100755 --- a/src/libsbmlnetwork_common.cpp +++ b/src/libsbmlnetwork_common.cpp @@ -80,21 +80,6 @@ bool isValueValid(const std::string& value, const std::vector& vali return false; } -std::string createErrorMessage(const std::string& value, std::vector validValues) { - std::string errorMessage = "error: " + value + " is not a valid value. It must be one of the following: "; - for (unsigned int i = 0; i < validValues.size(); i++) { - if (i != validValues.size() - 1) { - errorMessage += validValues[i]; - errorMessage += ", "; - } else { - errorMessage += "or "; - errorMessage += validValues[i]; - } - } - - return errorMessage; -} - const double roundToTwoDecimalPlaces(const double& value) { return round(value * 100.0) / 100.0; } \ No newline at end of file diff --git a/src/libsbmlnetwork_common.h b/src/libsbmlnetwork_common.h index 18ac890..c037077 100755 --- a/src/libsbmlnetwork_common.h +++ b/src/libsbmlnetwork_common.h @@ -27,8 +27,6 @@ std::string toLowerCase(const std::string& str); bool isValueValid(const std::string& value, const std::vector& validValues); -std::string createErrorMessage(const std::string& value, std::vector validValues); - const double roundToTwoDecimalPlaces(const double& value); #endif diff --git a/src/libsbmlnetwork_layout.cpp b/src/libsbmlnetwork_layout.cpp index caf95f0..e661c2a 100755 --- a/src/libsbmlnetwork_layout.cpp +++ b/src/libsbmlnetwork_layout.cpp @@ -1,6 +1,8 @@ #include "libsbmlnetwork_layout.h" #include "libsbmlnetwork_layout_helpers.h" -#include "libsbmlnetwork_sbmldocument_helpers.h" +#include "features/user_data/libsbmlnetwork_user_data.h" +#include "features/fix_elements/libsbmlnetwork_fix_element_position.h" +#include "features/fix_elements/libsbmlnetwork_fix_element_dimensions.h" namespace LIBSBMLNETWORK_CPP_NAMESPACE { @@ -40,7 +42,7 @@ int setDimensionWidth(Layout* layout, const double& width) { Dimensions* dimensions = getDimensions(layout); if (dimensions) { dimensions->setWidth(width); - setUserData(dimensions, "width", std::to_string(width)); + user_data_setUserData(dimensions, "width", std::to_string(width)); return 0; } } @@ -61,7 +63,7 @@ int setDimensionHeight(Layout* layout, const double& height) { Dimensions* dimensions = getDimensions(layout); if (dimensions) { dimensions->setHeight(height); - setUserData(dimensions, "height", std::to_string(height)); + user_data_setUserData(dimensions, "height", std::to_string(height)); return 0; } } @@ -741,7 +743,7 @@ int setPositionX(Layout* layout, GraphicalObject* graphicalObject, const double& double moveDistance = x - getPositionX(graphicalObject); if ((isSetCurve(graphicalObject) && !setPositionX(getCurve(graphicalObject), x)) || !setPositionX(getBoundingBox(graphicalObject), x)) { updateAssociatedTextGlyphsPositionX(layout, graphicalObject, moveDistance); - lockGraphicalObject(graphicalObject); + fix_elements_fixGraphicalObjectPosition(graphicalObject); return 0; } @@ -803,7 +805,7 @@ int setPositionY(Layout* layout, GraphicalObject* graphicalObject, const double& double moveDistance = y - getPositionY(graphicalObject); if ((isSetCurve(graphicalObject) && !setPositionY(getCurve(graphicalObject), y)) || !setPositionY(getBoundingBox(graphicalObject), y)) { updateAssociatedTextGlyphsPositionY(layout, graphicalObject, moveDistance); - lockGraphicalObject(graphicalObject); + fix_elements_fixGraphicalObjectPosition(graphicalObject); return 0; } @@ -893,7 +895,7 @@ int setDimensionWidth(Layout* layout, const std::string& id, unsigned int graphi int setDimensionWidth(Layout* layout, GraphicalObject* graphicalObject, const double& width) { double changedWidth = width - getDimensionWidth(graphicalObject); if (!setDimensionWidth(getBoundingBox(graphicalObject), width)) { - fixGraphicalObjectWidth(graphicalObject); + fix_elements_fixGraphicalObjectWidth(graphicalObject); updateAssociatedTextGlyphsDimensionWidth(layout, graphicalObject, changedWidth); return 0; } @@ -963,7 +965,7 @@ int setDimensionHeight(Layout* layout, const std::string& id, unsigned int graph int setDimensionHeight(Layout* layout, GraphicalObject* graphicalObject, const double& height) { double changedHeight = height - getDimensionHeight(graphicalObject); if (!setDimensionHeight(getBoundingBox(graphicalObject), height)) { - fixGraphicalObjectHeight(graphicalObject); + fix_elements_fixGraphicalObjectHeight(graphicalObject); updateAssociatedTextGlyphsDimensionHeight(layout, graphicalObject, changedHeight); return 0; } @@ -1287,7 +1289,7 @@ int setCurveSegmentStartPointX(Layout* layout, const std::string& id, unsigned i int setCurveSegmentStartPointX(GraphicalObject* graphicalObject, unsigned int curveSegmentIndex, const double& x) { if (!setCurveSegmentStartPointX(getCurve(graphicalObject), curveSegmentIndex, x)) { - lockGraphicalObject(graphicalObject); + fix_elements_fixGraphicalObjectPosition(graphicalObject); return 0; } @@ -1332,7 +1334,7 @@ int setCurveSegmentStartPointY(Layout* layout, const std::string& id, unsigned i int setCurveSegmentStartPointY(GraphicalObject* graphicalObject, unsigned int curveSegmentIndex, const double& y) { if (!setCurveSegmentStartPointY(getCurve(graphicalObject), curveSegmentIndex, y)) { - lockGraphicalObject(graphicalObject); + fix_elements_fixGraphicalObjectPosition(graphicalObject); return 0; } @@ -1377,7 +1379,7 @@ int setCurveSegmentEndPointX(Layout* layout, const std::string& id, unsigned int int setCurveSegmentEndPointX(GraphicalObject* graphicalObject, unsigned int curveSegmentIndex, const double& x) { if (!setCurveSegmentEndPointX(getCurve(graphicalObject), curveSegmentIndex, x)) { - lockGraphicalObject(graphicalObject); + fix_elements_fixGraphicalObjectPosition(graphicalObject); return 0; } @@ -1422,7 +1424,7 @@ int setCurveSegmentEndPointY(Layout* layout, const std::string& id, unsigned int int setCurveSegmentEndPointY(GraphicalObject* graphicalObject, unsigned int curveSegmentIndex, const double& y) { if (!setCurveSegmentEndPointY(getCurve(graphicalObject), curveSegmentIndex, y)) { - lockGraphicalObject(graphicalObject); + fix_elements_fixGraphicalObjectPosition(graphicalObject); return 0; } @@ -1467,7 +1469,7 @@ int setCurveSegmentBasePoint1X(Layout* layout, const std::string& id, unsigned i int setCurveSegmentBasePoint1X(GraphicalObject* graphicalObject, unsigned int curveSegmentIndex, const double& x) { if (!setCurveSegmentBasePoint1X(getCurve(graphicalObject), curveSegmentIndex, x)) { - lockGraphicalObject(graphicalObject); + fix_elements_fixGraphicalObjectPosition(graphicalObject); return 0; } @@ -1512,7 +1514,7 @@ int setCurveSegmentBasePoint1Y(Layout* layout, const std::string& id, unsigned i int setCurveSegmentBasePoint1Y(GraphicalObject* graphicalObject, unsigned int curveSegmentIndex, const double& y) { if (!setCurveSegmentBasePoint1Y(getCurve(graphicalObject), curveSegmentIndex, y)) { - lockGraphicalObject(graphicalObject); + fix_elements_fixGraphicalObjectPosition(graphicalObject); return 0; } @@ -1557,7 +1559,7 @@ int setCurveSegmentBasePoint2X(Layout* layout, const std::string& id, unsigned i int setCurveSegmentBasePoint2X(GraphicalObject* graphicalObject, unsigned int curveSegmentIndex, const double& x) { if (!setCurveSegmentBasePoint2X(getCurve(graphicalObject), curveSegmentIndex, x)) { - lockGraphicalObject(graphicalObject); + fix_elements_fixGraphicalObjectPosition(graphicalObject); return 0; } @@ -1602,7 +1604,7 @@ int setCurveSegmentBasePoint2Y(Layout* layout, const std::string& id, unsigned i int setCurveSegmentBasePoint2Y(GraphicalObject* graphicalObject, unsigned int curveSegmentIndex, const double& y) { if (!setCurveSegmentBasePoint2Y(getCurve(graphicalObject), curveSegmentIndex, y)) { - lockGraphicalObject(graphicalObject); + fix_elements_fixGraphicalObjectPosition(graphicalObject); return 0; } diff --git a/src/libsbmlnetwork_layout_helpers.cpp b/src/libsbmlnetwork_layout_helpers.cpp index 7e2ec5d..9c144cd 100755 --- a/src/libsbmlnetwork_layout_helpers.cpp +++ b/src/libsbmlnetwork_layout_helpers.cpp @@ -2,15 +2,15 @@ #include "libsbmlnetwork_common.h" #include "libsbmlnetwork_layout.h" #include "libsbmlnetwork_sbmldocument_layout.h" -#include "libsbmlnetwork_sbmldocument_helpers.h" +#include "features/error_log/libsbmlnetwork_error_log.h" +#include "features/user_data/libsbmlnetwork_user_data.h" +#include "features/defaults/libsbmlnetwork_defaults_layout.h" +#include "features/hide_elements/libsbmlnetwork_hide_species.h" +#include "features/set_layout_features/libsbmlnetwork_set_layout_features.h" #include #include -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif - namespace LIBSBMLNETWORK_CPP_NAMESPACE { LayoutModelPlugin* getLayoutModelPlugin(SBMLDocument* document) { @@ -38,7 +38,7 @@ SBasePlugin* getLayoutPlugin(SBMLDocument* document) { if (model) return model->getPlugin("layout"); else - addErrorToLog(document, "Failed to load model"); + error_log_addErrorToLog(document, "Failed to load model"); return NULL; } @@ -56,888 +56,43 @@ void enableLayoutPlugin(SBMLDocument* document) { document->setPackageRequired("layout", false); } -std::string getErrorLog(Layout* layout) { - std::string errorLog = ""; - if (layout) { - errorLog += prepareErrorMessage(getUserData(layout, "error_log"), errorLog); - for (unsigned int i = 0; i < layout->getNumCompartmentGlyphs(); i++) - errorLog += prepareErrorMessage(getErrorLog(layout->getCompartmentGlyph(i)), errorLog); - for (unsigned int i = 0; i < layout->getNumSpeciesGlyphs(); i++) - errorLog += prepareErrorMessage(getErrorLog(layout->getSpeciesGlyph(i)), errorLog); - for (unsigned int i = 0; i < layout->getNumReactionGlyphs(); i++) { - errorLog += prepareErrorMessage(getErrorLog(layout->getReactionGlyph(i)), errorLog); - for (unsigned int j = 0; j < layout->getReactionGlyph(i)->getNumSpeciesReferenceGlyphs(); j++) - errorLog += prepareErrorMessage(getErrorLog(layout->getReactionGlyph(i)->getSpeciesReferenceGlyph(j)), errorLog); - } - for (unsigned int i = 0; i < layout->getNumTextGlyphs(); i++) - errorLog += prepareErrorMessage(getErrorLog(layout->getTextGlyph(i)), errorLog); - } - - return errorLog; -} - -std::string getErrorLog(GraphicalObject* graphicalObject) { - std::string errorLog = ""; - if (graphicalObject) - errorLog += prepareErrorMessage(getUserData(graphicalObject, "error_log"), errorLog); - if (graphicalObject->getBoundingBox()) - errorLog += prepareErrorMessage(getErrorLog(graphicalObject->getBoundingBox()), errorLog); - if (isSetCurve(graphicalObject)) - errorLog += prepareErrorMessage(getErrorLog(getCurve(graphicalObject)), errorLog); - - return errorLog; -} - -std::string getErrorLog(BoundingBox* boundingBox) { - std::string errorLog = ""; - if (boundingBox) - errorLog += prepareErrorMessage(getUserData(boundingBox, "error_log"), errorLog); - - return errorLog; -} - -std::string getErrorLog(Curve* curve) { - std::string errorLog = ""; - if (curve) - errorLog += prepareErrorMessage(getUserData(curve, "error_log"), errorLog); - for (unsigned int i = 0; i < getNumCurveSegments(curve); i++) - errorLog += prepareErrorMessage(getErrorLog(getCurveSegment(curve, i)), errorLog); - - return errorLog; -} - -std::string getErrorLog(LineSegment* lineSegment) { - std::string errorLog = ""; - if (lineSegment) - errorLog += prepareErrorMessage(getUserData(lineSegment, "error_log"), errorLog); - - return errorLog; -} - -void clearErrorLog(Layout* layout) { - if (layout) { - setUserData(layout, "error_log", ""); - for (unsigned int i = 0; i < layout->getNumCompartmentGlyphs(); i++) - clearErrorLog(layout->getCompartmentGlyph(i)); - for (unsigned int i = 0; i < layout->getNumSpeciesGlyphs(); i++) - clearErrorLog(layout->getSpeciesGlyph(i)); - for (unsigned int i = 0; i < layout->getNumReactionGlyphs(); i++) { - clearErrorLog(layout->getReactionGlyph(i)); - for (unsigned int j = 0; j < layout->getReactionGlyph(i)->getNumSpeciesReferenceGlyphs(); j++) - clearErrorLog(layout->getReactionGlyph(i)->getSpeciesReferenceGlyph(j)); - } - for (unsigned int i = 0; i < layout->getNumTextGlyphs(); i++) - clearErrorLog(layout->getTextGlyph(i)); - } -} - -void clearErrorLog(GraphicalObject* graphicalObject) { - if (graphicalObject) { - setUserData(graphicalObject, "error_log", ""); - if (graphicalObject->getBoundingBox()) - clearErrorLog(graphicalObject->getBoundingBox()); - if (isSetCurve(graphicalObject)) - clearErrorLog(getCurve(graphicalObject)); - } -} - -void clearErrorLog(BoundingBox* boundingBox) { - if (boundingBox) - setUserData(boundingBox, "error_log", ""); -} - -void clearErrorLog(Curve* curve) { - if (curve) { - setUserData(curve, "error_log", ""); - for (unsigned int i = 0; i < getNumCurveSegments(curve); i++) - clearErrorLog(getCurveSegment(curve, i)); - } -} - -void clearErrorLog(LineSegment* lineSegment) { - if (lineSegment) - setUserData(lineSegment, "error_log", ""); -} - -void freeUserData(Layout* layout) { - if (layout->isSetUserData()) { - auto userData = (std::map*)layout->getUserData(); - if (userData) { - delete userData; - } - } - freeUserData(layout->getDimensions()); - for (unsigned int i = 0; i < layout->getNumCompartmentGlyphs(); i++) { - CompartmentGlyph* compartmentGlyph = layout->getCompartmentGlyph(i); - freeUserData(compartmentGlyph); - freeUserData(compartmentGlyph->getBoundingBox()); - } - for (unsigned int i = 0; i < layout->getNumSpeciesGlyphs(); i++) { - SpeciesGlyph* speciesGlyph = layout->getSpeciesGlyph(i); - freeUserData(speciesGlyph); - freeUserData(speciesGlyph->getBoundingBox()); - } - for (unsigned int i = 0; i < layout->getNumReactionGlyphs(); i++) { - ReactionGlyph* reactionGlyph = layout->getReactionGlyph(i); - freeUserData(reactionGlyph); - freeUserData(reactionGlyph->getBoundingBox()); - freeUserData(reactionGlyph->getCurve()); - for (unsigned int j = 0; j < reactionGlyph->getNumSpeciesReferenceGlyphs(); j++) { - SpeciesReferenceGlyph* speciesReferenceGlyph = reactionGlyph->getSpeciesReferenceGlyph(j); - freeUserData(speciesReferenceGlyph); - freeUserData(speciesReferenceGlyph->getCurve()); - } - } -} - -std::vector> getUserData(Layout* layout) { - std::vector> userData; - for (unsigned int i = 0; i < layout->getNumCompartmentGlyphs(); i++) { - auto compartmentGlyphUserData = layout->getCompartmentGlyph(i)->getUserData(); - if (compartmentGlyphUserData) - userData.push_back(*(std::map*)compartmentGlyphUserData); - } - for (unsigned int i = 0; i < layout->getNumSpeciesGlyphs(); i++) { - auto speciesGlyphUserData = layout->getSpeciesGlyph(i)->getUserData(); - if (speciesGlyphUserData) - userData.push_back(*(std::map*)speciesGlyphUserData); - } - for (unsigned int i = 0; i < layout->getNumReactionGlyphs(); i++) { - auto reactionGlyphUserData = layout->getReactionGlyph(i)->getUserData(); - if (reactionGlyphUserData) - userData.push_back(*(std::map*)reactionGlyphUserData); - for (unsigned int j = 0; j < layout->getReactionGlyph(i)->getNumSpeciesReferenceGlyphs(); j++) { - auto speciesReferenceGlyphUserData = layout->getReactionGlyph(i)->getSpeciesReferenceGlyph(j)->getUserData(); - if (speciesReferenceGlyphUserData) - userData.push_back(*(std::map*)speciesReferenceGlyphUserData); - } - } - - return userData; -} - -void setUserData(GraphicalObject* graphicalObject, const std::string& key, const std::string& value) { - if (!graphicalObject->isSetUserData()) { - graphicalObject->setUserData(new std::map()); - setUserData(graphicalObject, "id", graphicalObject->getId()); - setUserData(graphicalObject, "entity_id", getEntityId(graphicalObject)); - } - auto userData = (std::map*)graphicalObject->getUserData(); - (*userData)[key] = value; -} - -void setPositionData(GraphicalObject* graphicalObject) { - setUserData(graphicalObject, "x", std::to_string(getPositionX(graphicalObject))); - setUserData(graphicalObject, "y", std::to_string(getPositionY(graphicalObject))); -} - -void unsetPositionData(GraphicalObject* graphicalObject) { - setUserData(graphicalObject, "x", ""); - setUserData(graphicalObject, "y", ""); -} - -void setPositionData(SpeciesReferenceGlyph* speciesReferenceGlyph) { - if (speciesReferenceGlyph) { - Curve* curve = getCurve(speciesReferenceGlyph); - for (unsigned int i = 0; i < getNumCurveSegments(curve); i++) { - setUserData(speciesReferenceGlyph, std::to_string(i) + ":start_x", std::to_string(getCurveSegmentStartPointX(curve, i))); - setUserData(speciesReferenceGlyph, std::to_string(i) + ":start_y", std::to_string(getCurveSegmentStartPointY(curve, i))); - setUserData(speciesReferenceGlyph, std::to_string(i) + ":end_x", std::to_string(getCurveSegmentEndPointX(curve, i))); - setUserData(speciesReferenceGlyph, std::to_string(i) + ":end_y", std::to_string(getCurveSegmentEndPointY(curve, i))); - if (isCubicBezier(curve, i)) { - setUserData(speciesReferenceGlyph, std::to_string(i) + ":b1_x", std::to_string(getCurveSegmentBasePoint1X(curve, i))); - setUserData(speciesReferenceGlyph, std::to_string(i) + ":b1_y", std::to_string(getCurveSegmentBasePoint1Y(curve, i))); - setUserData(speciesReferenceGlyph, std::to_string(i) + ":b2_x", std::to_string(getCurveSegmentBasePoint2X(curve, i))); - setUserData(speciesReferenceGlyph, std::to_string(i) + ":b2_y", std::to_string(getCurveSegmentBasePoint2Y(curve, i))); - } - } - } -} - -void unsetPositionData(SpeciesReferenceGlyph* speciesReferenceGlyph) { - if (speciesReferenceGlyph) { - Curve* curve = getCurve(speciesReferenceGlyph); - for (unsigned int i = 0; i < getNumCurveSegments(curve); i++) { - setUserData(curve, std::to_string(i) + ":start_x", ""); - setUserData(curve, std::to_string(i) + ":start_y", ""); - setUserData(curve, std::to_string(i) + ":end_x", ""); - setUserData(curve, std::to_string(i) + ":end_y", ""); - setUserData(curve, std::to_string(i) + ":b1_x", ""); - setUserData(curve, std::to_string(i) + ":b1_y", ""); - setUserData(curve, std::to_string(i) + ":b2_x", ""); - setUserData(curve, std::to_string(i) + ":b2_y", ""); - } - } -} - -void setDefaultLayoutId(Layout* layout) { - if (!layout->isSetId()) - layout->setId(getDefaultLayoutId()); -} - -const std::string getDefaultLayoutId() { - return "libSBMLNetwork_Layout"; -} - -void setDefaultLayoutDimensions(Layout* layout) { - Dimensions* dimensions = layout->getDimensions(); - if (!dimensions) { - dimensions = new Dimensions(layout->getLevel(), layout->getVersion(), layout->getPackageVersion()); - layout->setDimensions(dimensions); - } - if (dimensions->getWidth() < 0.0001) - dimensions->setWidth(1024.0); - if (dimensions->getHeight() < 0.0001) - dimensions->setHeight(1024.0); -} - -const double getSpeciesDefaultWidth() { - return 60.0; -} - -const double getSpeciesDefaultHeight() { - return 36.0; -} - -const double getEmptySpeciesDefaultRadius() { - return 15.0; -} - -const double getReactionDefaultWidth() { - return 30.0; -} - -const double getReactionDefaultHeight() { - return 20.0; -} - -void lockGraphicalObjects(Layout* layout, std::set > lockedNodesSet, const bool resetLockedElements) { - lockCompartmentGlyphs(layout, resetLockedElements); - lockSpeciesGlyphs(layout, lockedNodesSet, resetLockedElements); - lockReactionGlyphs(layout, lockedNodesSet, resetLockedElements); -} - -void lockCompartmentGlyphs(Layout* layout, const bool resetLockedElements) { - if (resetLockedElements) { - for (unsigned int i = 0; i < layout->getNumCompartmentGlyphs(); i++) { - CompartmentGlyph* compartmentGlyph = layout->getCompartmentGlyph(i); - if (getUserData(compartmentGlyph, "locked") == "true") - unlockGraphicalObject(compartmentGlyph); - if (getUserData(compartmentGlyph, "fixed_width") == "true") - unfixGraphicalObjectWidth(compartmentGlyph); - if (getUserData(compartmentGlyph, "fixed_height") == "true") - unfixGraphicalObjectHeight(compartmentGlyph); - } - } -} - -void lockSpeciesGlyphs(Layout* layout, std::set > lockedNodesSet, const bool resetLockedElements) { - if (resetLockedElements) { - for (unsigned int i = 0; i < layout->getNumSpeciesGlyphs(); i++) { - SpeciesGlyph* speciesGlyph = layout->getSpeciesGlyph(i); - if (getUserData(speciesGlyph, "locked") == "true") - unlockGraphicalObject(speciesGlyph); - if (getUserData(speciesGlyph, "fixed_width") == "true") - unfixGraphicalObjectWidth(speciesGlyph); - if (getUserData(speciesGlyph, "fixed_height") == "true") - unfixGraphicalObjectHeight(speciesGlyph); - } - } - - for (std::set >::const_iterator lockedNodeIt = lockedNodesSet.cbegin(); lockedNodeIt != lockedNodesSet.cend(); lockedNodeIt++) { - std::vector speciesGlyphs = getAssociatedSpeciesGlyphsWithSpeciesId(layout, lockedNodeIt->first); - if (lockedNodeIt->second < speciesGlyphs.size()) { - lockGraphicalObject(speciesGlyphs.at(lockedNodeIt->second)); - } - } -} - -void lockReactionGlyphs(Layout* layout, std::set > lockedNodesSet, const bool resetLockedElements) { - if (resetLockedElements) { - for (unsigned int i = 0; i < layout->getNumReactionGlyphs(); i++) { - ReactionGlyph* reactionGlyph = layout->getReactionGlyph(i); - if (getUserData(reactionGlyph, "locked") == "true") - unlockGraphicalObject(reactionGlyph); - if (getUserData(reactionGlyph, "fixed_width") == "true") - unfixGraphicalObjectWidth(reactionGlyph); - if (getUserData(reactionGlyph, "fixed_height") == "true") - unfixGraphicalObjectHeight(reactionGlyph); - for (unsigned int j = 0; j < reactionGlyph->getNumSpeciesReferenceGlyphs(); j++) { - SpeciesReferenceGlyph *speciesReferenceGlyph = reactionGlyph->getSpeciesReferenceGlyph(j); - if (getUserData(speciesReferenceGlyph, "locked") == "true") - unlockGraphicalObject(speciesReferenceGlyph); - } - } - } - - for (std::set >::const_iterator lockedNodeIt = lockedNodesSet.cbegin(); lockedNodeIt != lockedNodesSet.cend(); lockedNodeIt++) { - std::vector reactionGlyphs = getAssociatedReactionGlyphsWithReactionId(layout, lockedNodeIt->first); - if (lockedNodeIt->second < reactionGlyphs.size()) { - lockGraphicalObject(reactionGlyphs.at(lockedNodeIt->second)); - } - } -} - -void lockGraphicalObject(GraphicalObject* graphicalObject) { - setUserData(graphicalObject, "locked", "true"); - if (isSpeciesReferenceGlyph(graphicalObject)) - setPositionData((SpeciesReferenceGlyph*)graphicalObject); - else - setPositionData(graphicalObject); -} - -void unlockGraphicalObject(GraphicalObject* graphicalObject) { - setUserData(graphicalObject, "locked", "false"); - if (isSpeciesReferenceGlyph(graphicalObject)) - unsetPositionData((SpeciesReferenceGlyph*)graphicalObject); - else - unsetPositionData(graphicalObject); -} - -std::vector getLockedGraphicalObjects(std::vector graphicalObjects) { - std::vector lockedGraphicalObjects; - for (unsigned int i = 0; i < graphicalObjects.size(); i++) - if (getUserData(graphicalObjects.at(i), "locked") == "true") - lockedGraphicalObjects.push_back(graphicalObjects.at(i)); - - return lockedGraphicalObjects; -} - -void fixGraphicalObjectWidth(GraphicalObject* graphicalObject) { - setUserData(graphicalObject, "fixed_width", "true"); - setUserData(graphicalObject, "width", std::to_string(graphicalObject->getBoundingBox()->width())); -} - -void unfixGraphicalObjectWidth(GraphicalObject* graphicalObject) { - setUserData(graphicalObject, "fixed_width", "false"); - setUserData(graphicalObject, "width", ""); -} - -void fixGraphicalObjectHeight(GraphicalObject* graphicalObject) { - setUserData(graphicalObject, "fixed_height", "true"); - setUserData(graphicalObject, "height", std::to_string(graphicalObject->getBoundingBox()->height())); -} - -void unfixGraphicalObjectHeight(GraphicalObject* graphicalObject) { - setUserData(graphicalObject, "fixed_height", "false"); - setUserData(graphicalObject, "height", ""); -} - -void clearGraphicalObjects(Layout* layout) { - clearCompartmentGlyphs(layout); - clearSpeciesGlyphs(layout); - clearReactionGlyphs(layout); - clearTextGlyphs(layout); -} - -void clearCompartmentGlyphs(Layout* layout) { - while (layout->getNumCompartmentGlyphs()) { - freeUserData(layout->getCompartmentGlyph(0)); - delete layout->removeCompartmentGlyph(0); - } -} - -void clearSpeciesGlyphs(Layout* layout) { - while (layout->getNumSpeciesGlyphs()) { - freeUserData(layout->getSpeciesGlyph(0)); - delete layout->removeSpeciesGlyph(0); - } -} - -void clearReactionGlyphs(Layout* layout) { - while (layout->getNumReactionGlyphs()) { - clearReactionGlyphSpeciesReferenceGlyphs(layout->getReactionGlyph(0)); - freeUserData(layout->getReactionGlyph(0)); - delete layout->removeReactionGlyph(0); - } - -} - -void clearReactionGlyphSpeciesReferenceGlyphs(ReactionGlyph* reactionGlyph) { - while (reactionGlyph->getNumSpeciesReferenceGlyphs()) { - freeUserData(reactionGlyph->getSpeciesReferenceGlyph(0)); - delete reactionGlyph->removeSpeciesReferenceGlyph(0); - } -} - -void clearTextGlyphs(Layout* layout) { - while (layout->getNumTextGlyphs()) { - freeUserData(layout->getTextGlyph(0)); - delete layout->removeTextGlyph(0); - } -} - -void clearReactionTextGlyphs(Layout* layout) { - for (unsigned int i = 0; i < layout->getNumReactionGlyphs(); i++) { - ReactionGlyph* reactionGlyph = layout->getReactionGlyph(i); - std::vector textGlyphs = getAssociatedTextGlyphsWithGraphicalObject(layout, reactionGlyph); - for (unsigned int j = 0; j < textGlyphs.size(); j++) { - freeUserData(textGlyphs.at(j)); - delete layout->removeTextGlyph(textGlyphs.at(j)->getId()); - } - } -} - -void setCompartmentGlyphs(Model* model, Layout* layout, const std::vector>& userData) { - for (unsigned int i = 0; i < model->getNumCompartments(); i++) { - Compartment *compartment = model->getCompartment(i); - CompartmentGlyph *compartmentGlyph = createCompartmentGlyph(layout, compartment->getId(), userData); - setGraphicalObjectBoundingBox(compartmentGlyph); - } -} - -void setReactionGlyphs(Model* model, Layout* layout, const int maxNumConnectedEdges, const std::vector>& userData) { - for (unsigned int i = 0; i < model->getNumReactions(); i++) { - Reaction* reaction = model->getReaction(i); - ReactionGlyph* reactionGlyph = createReactionGlyph(layout, reaction->getId(), userData); - setReactantGlyphs(layout, reaction, reactionGlyph, maxNumConnectedEdges, userData); - setProductGlyphs(layout, reaction, reactionGlyph, maxNumConnectedEdges, userData); - setModifierGlyphs(layout, reaction, reactionGlyph, maxNumConnectedEdges, userData); - setEmptySpeciesReferenceGlyphs(model, layout, reactionGlyph, userData); - } -} - -void setReactantGlyphs(Layout* layout, Reaction* reaction, ReactionGlyph* reactionGlyph, const int maxNumConnectedEdges, const std::vector>& userData) { - for (unsigned int i = 0; i < reaction->getNumReactants(); i++) { - SimpleSpeciesReference* speciesReference = reaction->getReactant(i); - if (!isSpeciesGlyphHidden(layout, reactionGlyph, speciesReference->getSpecies())) { - int stoichiometry = getStoichiometryAsInteger(speciesReference); - for (unsigned int stoichiometryIndex = 0; stoichiometryIndex < stoichiometry; stoichiometryIndex++) { - SpeciesReferenceGlyph *speciesReferenceGlyph = createSpeciesReferenceGlyph(layout, reactionGlyph, speciesReference->getSpecies(), stoichiometryIndex, maxNumConnectedEdges, userData); - speciesReferenceGlyph->setRole(SPECIES_ROLE_SUBSTRATE); - } - } - } -} - -void setProductGlyphs(Layout* layout, Reaction* reaction, ReactionGlyph* reactionGlyph, const int maxNumConnectedEdges, const std::vector>& userData) { - for (unsigned int i = 0; i < reaction->getNumProducts(); i++) { - SimpleSpeciesReference* speciesReference = reaction->getProduct(i); - if (!isSpeciesGlyphHidden(layout, reactionGlyph, speciesReference->getSpecies())) { - int stoichiometry = getStoichiometryAsInteger(speciesReference); - for (unsigned int stoichiometryIndex = 0; stoichiometryIndex < stoichiometry; stoichiometryIndex++) { - SpeciesReferenceGlyph* speciesReferenceGlyph = createSpeciesReferenceGlyph(layout, reactionGlyph, speciesReference->getSpecies(), stoichiometryIndex, maxNumConnectedEdges, userData); - speciesReferenceGlyph->setRole(SPECIES_ROLE_PRODUCT); - } - } - } -} - -void setModifierGlyphs(Layout* layout, Reaction* reaction, ReactionGlyph* reactionGlyph, const int maxNumConnectedEdges, const std::vector>& userData) { - for (unsigned int i = 0; i < reaction->getNumModifiers(); i++) { - SimpleSpeciesReference* speciesReference = reaction->getModifier(i); - if (!isSpeciesGlyphHidden(layout, reactionGlyph, speciesReference->getSpecies())) { - SpeciesReferenceGlyph* speciesReferenceGlyph = createSpeciesReferenceGlyph(layout, reactionGlyph, speciesReference->getSpecies(), 0, maxNumConnectedEdges, userData); - if (speciesReference->getSBOTermID() == "SBO:0000020") - speciesReferenceGlyph->setRole(SPECIES_ROLE_INHIBITOR); - else - speciesReferenceGlyph->setRole(SPECIES_ROLE_MODIFIER); - } - } -} - -void setEmptySpeciesReferenceGlyphs(Model* model, Layout* layout, ReactionGlyph* reactionGlyph, const std::vector>& userData) { - Reaction* reaction = findReactionGlyphReaction(model, reactionGlyph); - if (reaction->getNumReactants() == 0) { - SpeciesReferenceGlyph* emptyReactantGlyph = createEmptySpeciesReferenceGlyph(model, layout, reactionGlyph); - emptyReactantGlyph->setRole(SPECIES_ROLE_SUBSTRATE); - setGraphicalObjectUserData(emptyReactantGlyph, userData); - } - else if (reaction->getNumProducts() == 0) { - SpeciesReferenceGlyph* emptyProductGlyph = createEmptySpeciesReferenceGlyph(model, layout, reactionGlyph); - emptyProductGlyph->setRole(SPECIES_ROLE_PRODUCT); - setGraphicalObjectUserData(emptyProductGlyph, userData); - } -} - -SpeciesReferenceGlyph* createEmptySpeciesReferenceGlyph(Model* model, Layout* layout, ReactionGlyph* reactionGlyph) { - SpeciesGlyph* emptySpeciesGlyph = createEmptySpeciesGlyph(model, layout, reactionGlyph); - return createEmptySpeciesReferenceGlyph(layout, reactionGlyph, emptySpeciesGlyph); -} - -SpeciesGlyph* createEmptySpeciesGlyph(Model* model, Layout* layout, ReactionGlyph* reactionGlyph) { - SpeciesGlyph* emptySpeciesGlyph = createEmptySpeciesGlyph(layout, reactionGlyph->getId()); - CompartmentGlyph* compartmentGlyph = getCompartmentGlyphOfReactionGlyph(model, layout, reactionGlyph); - if (compartmentGlyph) - setUserData(emptySpeciesGlyph, "compartment", compartmentGlyph->getCompartmentId()); - setUserData(emptySpeciesGlyph, "width", std::to_string(2* getEmptySpeciesDefaultRadius())); - setUserData(emptySpeciesGlyph, "height", std::to_string(2* getEmptySpeciesDefaultRadius())); - setGraphicalObjectBoundingBox(emptySpeciesGlyph); - - return emptySpeciesGlyph; -} - -SpeciesReferenceGlyph* createEmptySpeciesReferenceGlyph(Layout* layout, ReactionGlyph* reactionGlyph, SpeciesGlyph* emptySpeciesGlyph) { - SpeciesReferenceGlyph* emptySpeciesReferenceGlyph = layout->createSpeciesReferenceGlyph(); - emptySpeciesReferenceGlyph->setId(reactionGlyph->getId() + "_EmptySpeciesReferenceGlyph"); - emptySpeciesReferenceGlyph->setSpeciesGlyphId(emptySpeciesGlyph->getId()); - setSpeciesReferenceGlyphCurve(emptySpeciesReferenceGlyph); - - return emptySpeciesReferenceGlyph; -} - -bool isSetEmptySpeciesGlyph(Layout* layout, SpeciesReferenceGlyph* speciesReferenceGlyph) { - if (layout && speciesReferenceGlyph) { - SpeciesGlyph* speciesGlyph = layout->getSpeciesGlyph(speciesReferenceGlyph->getSpeciesGlyphId()); - return isEmptySpeciesGlyph(speciesGlyph); - } - - return false; -} - -const std::string getEmptySpeciesGlyphId(Layout* layout, SpeciesReferenceGlyph* speciesReferenceGlyph) { - if (isSetEmptySpeciesGlyph(layout, speciesReferenceGlyph)) - return layout->getSpeciesGlyph(speciesReferenceGlyph->getSpeciesGlyphId())->getId(); - - return ""; -} - -int createAliasSpeciesGlyph(Layout* layout, const std::string speciesId, ReactionGlyph* reactionGlyph) { - if (reactionGlyph) { - std::vector speciesGlyphReferences = getSpeciesReferencesAssociatedWithSpecies(layout, reactionGlyph, speciesId); - if (canHaveAlias(layout, speciesGlyphReferences)) { - SpeciesGlyph* aliasSpeciesGlyph = createAliasSpeciesGlyph(layout, speciesId, speciesGlyphReferences); - if (aliasSpeciesGlyph) { - setAliasGraphicalObjectPosition(aliasSpeciesGlyph, reactionGlyph); - setAliasSpeciesGlyphDimensions(aliasSpeciesGlyph, reactionGlyph); - setAliasSpeciesGlyphTextGlyph(layout, aliasSpeciesGlyph); - return 0; - } - } - } - - return -1; -} - -SpeciesGlyph* createAliasSpeciesGlyph(Layout* layout, SpeciesGlyph* speciesGlyph) { - SpeciesGlyph* aliasSpeciesGlyph = NULL; - if (speciesGlyph) { - aliasSpeciesGlyph = createSpeciesGlyph(layout, speciesGlyph->getSpeciesId()); - setAliasGraphicalObjectPosition(aliasSpeciesGlyph, speciesGlyph, getAliasSpeciesGlyphPadding()); - setAliasSpeciesGlyphDimensions(aliasSpeciesGlyph, speciesGlyph); - setAliasSpeciesGlyphTextGlyph(layout, aliasSpeciesGlyph); - } - - return aliasSpeciesGlyph; -} - -SpeciesGlyph* createAliasSpeciesGlyph(Layout* layout, const std::string& speciesId, std::vector speciesGlyphReferences) { - SpeciesGlyph* aliasSpeciesGlyph = NULL; - if (speciesGlyphReferences.size()) { - aliasSpeciesGlyph = createSpeciesGlyph(layout, speciesId); - while (speciesGlyphReferences.size()) { - SpeciesReferenceGlyph* speciesReferenceGlyph = speciesGlyphReferences.back(); - speciesReferenceGlyph->setId(getIdOfSpeciesReferenceGlyphConnectedToNewSpeciesGlyph(speciesReferenceGlyph->getId(), speciesReferenceGlyph->getSpeciesGlyphId(), aliasSpeciesGlyph->getId())); - speciesReferenceGlyph->setSpeciesGlyphId(aliasSpeciesGlyph->getId()); - speciesGlyphReferences.pop_back(); - } - } - - return aliasSpeciesGlyph; -} - -SpeciesGlyph* getSpeciesGlyph(Layout* layout, const std::string& speciesId, const int maxNumConnectedEdges, const std::vector>& userData) { - std::vector speciesGlyphs = getAssociatedSpeciesGlyphsWithSpeciesId(layout, speciesId); - if (speciesGlyphs.size()) { - if (getConnectedSpeciesGlyphReferences(layout, speciesGlyphs.back()).size() >= maxNumConnectedEdges) - return createSpeciesGlyph(layout, speciesId, userData); - - return speciesGlyphs.back(); - } - - return createSpeciesGlyph(layout, speciesId, userData); -} - -int setSpeciesGlyphIndexInReactionGlyph(Layout* layout, const std::string speciesId, ReactionGlyph* reactionGlyph, const unsigned int index) { - std::vector speciesGlyphs = getAssociatedSpeciesGlyphsWithSpeciesId(layout, speciesId); - std::vector speciesReferenceGlyphs = getSpeciesReferencesAssociatedWithSpecies(layout, reactionGlyph, speciesId); - int originalSpeciesGlyphIndex = getIndexOfConnectedSpeciesGlyph(speciesReferenceGlyphs, speciesGlyphs); - if (originalSpeciesGlyphIndex != -1 && originalSpeciesGlyphIndex != index && index < speciesGlyphs.size()) { - SpeciesGlyph* originalSpeciesGlyph = speciesGlyphs.at(originalSpeciesGlyphIndex); - SpeciesGlyph* newSpeciesGlyph = speciesGlyphs.at(index); - for (unsigned int i = 0; i < speciesReferenceGlyphs.size(); i++) { - SpeciesReferenceGlyph* speciesReferenceGlyph = speciesReferenceGlyphs.at(i); - speciesReferenceGlyph->setId(getIdOfSpeciesReferenceGlyphConnectedToNewSpeciesGlyph(speciesReferenceGlyph->getId(), originalSpeciesGlyph->getId(), newSpeciesGlyph->getId())); - speciesReferenceGlyph->setSpeciesGlyphId(newSpeciesGlyph->getId()); - } - if (!getSpeciesReferencesAssociatedWithSpeciesGlyph(layout, originalSpeciesGlyph->getId()).size()) { - freeUserData(originalSpeciesGlyph); - layout->removeSpeciesGlyph(originalSpeciesGlyph->getId()); - } - - return 0; - } - - return -1; -} - -int makeSpeciesGlyphsVisible(Model* model, Layout* layout, std::set > species, bool visible) { - for (std::set >::const_iterator speciesIt = species.cbegin(); speciesIt != species.cend(); speciesIt++) { - if (makeSpeciesGlyphVisible(getReactionGlyph(layout, std::get<1>(*speciesIt), std::get<2>(*speciesIt)), std::get<0>(*speciesIt), visible)) - return -1; - } - - return 0; -} - -int makeSpeciesGlyphVisible(ReactionGlyph* reactionGlyph, const std::string speciesId, bool visible) { - if (!visible) - return hideSpeciesGlyph(reactionGlyph, speciesId); - else - return unHideSpeciesGlyph(reactionGlyph, speciesId); -} - -int hideSpeciesGlyph(SBase* sBase, const std::string speciesId) { - if (sBase) { - std::string hiddenSpeciesIds = getUserData(sBase, "hidden_species_ids"); - if (hiddenSpeciesIds.find(speciesId) == std::string::npos) { - if (hiddenSpeciesIds.size()) - hiddenSpeciesIds += ","; - hiddenSpeciesIds += speciesId; - if (isGraphicalObject(sBase)) - setUserData((GraphicalObject*)sBase, "hidden_species_ids", hiddenSpeciesIds); - else - setUserData(sBase, "hidden_species_ids", hiddenSpeciesIds); - } - - return 0; - } - - return -1; -} - -int unHideSpeciesGlyph(SBase* sBase, const std::string speciesId) { - if (sBase) { - std::string hiddenSpeciesIds = getUserData(sBase, "hidden_species_ids"); - size_t found = hiddenSpeciesIds.find(speciesId); - if (found != std::string::npos) { - hiddenSpeciesIds.erase(found, speciesId.size()); - if (hiddenSpeciesIds.back() == ',') - hiddenSpeciesIds.pop_back(); - if (isGraphicalObject(sBase)) - setUserData((GraphicalObject*)sBase, "hidden_species_ids", hiddenSpeciesIds); - else - setUserData(sBase, "hidden_species_ids", hiddenSpeciesIds); - } - - return 0; - } - - return -1; -} - -const bool isSpeciesGlyphHidden(Layout* layout, ReactionGlyph* reactionGlyph, const std::string speciesId) { - return getUserData(layout, "hidden_species_ids").find(speciesId) != std::string::npos || getUserData(reactionGlyph, "hidden_species_ids").find(speciesId) != std::string::npos; -} - -const bool canHaveAlias(Layout* layout, std::vector connectedSpeciesGlyphReferencesOfReactionGlyph) { - if (connectedSpeciesGlyphReferencesOfReactionGlyph.size()) { - SpeciesGlyph* speciesGlyph = layout->getSpeciesGlyph(connectedSpeciesGlyphReferencesOfReactionGlyph.at(0)->getSpeciesGlyphId()); - std::vector connectedSpeciesGlyphReferencesOfSpeciesGlyph = getConnectedSpeciesGlyphReferences(layout, speciesGlyph); - if (connectedSpeciesGlyphReferencesOfSpeciesGlyph.size() > connectedSpeciesGlyphReferencesOfReactionGlyph.size()) - return true; - } - - return false; -} - -void setAliasGraphicalObjectPosition(GraphicalObject* aliasGraphicalObject, GraphicalObject* graphicalObject, const double& padding) { - double x = getPositionX(graphicalObject); - double y = getPositionY(graphicalObject); - if (isSetCurve(aliasGraphicalObject)) { - setPositionX(getCurve(aliasGraphicalObject), x + padding); - setPositionY(getCurve(aliasGraphicalObject), y + padding); - } - else { - setPositionX(getBoundingBox(aliasGraphicalObject), x + padding); - setPositionY(getBoundingBox(aliasGraphicalObject), y + padding); - } -} - -void setAliasSpeciesGlyphDimensions(SpeciesGlyph* aliasSpeciesGlyph, GraphicalObject* graphicalObject) { - double width = getSpeciesDefaultWidth();; - if (isSpeciesGlyph(graphicalObject)) - width = getDimensionWidth(graphicalObject); - aliasSpeciesGlyph->getBoundingBox()->setWidth(width); - double height = getSpeciesDefaultHeight(); - if (isSpeciesGlyph(graphicalObject)) - height = getDimensionHeight(graphicalObject); - aliasSpeciesGlyph->getBoundingBox()->setHeight(height); -} - -void setAliasSpeciesGlyphTextGlyph(Layout* layout, SpeciesGlyph* aliasSpeciesGlyph) { - TextGlyph* textGlyph = createAssociatedTextGlyph(layout, aliasSpeciesGlyph); - setTextGlyphBoundingBox(textGlyph, aliasSpeciesGlyph); -} - -std::vector getConnectedSpeciesGlyphReferences(Layout* layout, SpeciesGlyph* speciesGlyph) { - std::vector speciesGlyphReferences; - for (unsigned int i = 0; i < layout->getNumReactionGlyphs(); i++) { - ReactionGlyph* reactionGlyph = layout->getReactionGlyph(i); - for (unsigned int j = 0; j < reactionGlyph->getNumSpeciesReferenceGlyphs(); j++) { - SpeciesReferenceGlyph* speciesReferenceGlyph = reactionGlyph->getSpeciesReferenceGlyph(j); - if (speciesReferenceGlyph->getSpeciesGlyphId() == speciesGlyph->getId()) - speciesGlyphReferences.push_back(speciesReferenceGlyph); - } - } - - return speciesGlyphReferences; -} - -int getNumRequiredAliasSpeciesGlyphs(const int numConnectedEdges, const int maxNumConnectedEdges) { - int numRequiredAliasSpeciesGlyphs = 0; - if (numConnectedEdges > maxNumConnectedEdges) - numRequiredAliasSpeciesGlyphs = numConnectedEdges / maxNumConnectedEdges; - if (numConnectedEdges % maxNumConnectedEdges == 0) - numRequiredAliasSpeciesGlyphs--; - - return numRequiredAliasSpeciesGlyphs; -} - -int createAliasReactionGlyph(SBMLDocument* document, Layout* layout, ReactionGlyph* reactionGlyph) { - if (document && reactionGlyph) { - ReactionGlyph* aliasReactionGlyph = createAliasReactionGlyph(layout, reactionGlyph); - return createAliasSpeciesReferenceGlyphs(document, layout, reactionGlyph, aliasReactionGlyph); - } - - return -1; -} - -ReactionGlyph* createAliasReactionGlyph(Layout* layout, ReactionGlyph* reactionGlyph) { - ReactionGlyph* aliasReactionGlyph = NULL; - if (reactionGlyph) { - aliasReactionGlyph = createReactionGlyph(layout, reactionGlyph->getReactionId()); - setAliasGraphicalObjectPosition(aliasReactionGlyph, reactionGlyph, getAliasReactionGlyphPadding()); - setAliasReactionGlyphTextGlyph(layout, aliasReactionGlyph, reactionGlyph); - } - - return aliasReactionGlyph; -} - -void setAliasReactionGlyphTextGlyph(Layout* layout, ReactionGlyph* aliasReactionGlyph, ReactionGlyph* reactionGlyph) { - std::vector textGlyphs = getAssociatedTextGlyphsWithGraphicalObject(layout, reactionGlyph); - if (textGlyphs.size()) { - TextGlyph* textGlyph = createAssociatedTextGlyph(layout, aliasReactionGlyph); - setTextGlyphBoundingBox(textGlyph, textGlyphs.at(0)); - } -} - -int createAliasSpeciesReferenceGlyphs(SBMLDocument* document, Layout* layout, ReactionGlyph* referenceReactionGlyph, ReactionGlyph* reactionGlyph) { - std::map speciesGlyphAliasSpeciesGlyphIds; - for (unsigned int i = 0; i < referenceReactionGlyph->getNumSpeciesReferenceGlyphs(); i++) { - SpeciesReferenceGlyph *speciesReferenceGlyph = referenceReactionGlyph->getSpeciesReferenceGlyph(i); - SpeciesGlyph *speciesGlyph = layout->getSpeciesGlyph(speciesReferenceGlyph->getSpeciesGlyphId()); - if (speciesGlyph) { - SpeciesGlyph *connectedSpeciesGlyph = NULL; - if (speciesGlyphAliasSpeciesGlyphIds.find(speciesGlyph->getId()) == speciesGlyphAliasSpeciesGlyphIds.end()) - connectedSpeciesGlyph = createAliasSpeciesGlyph(layout, speciesGlyph); - else - connectedSpeciesGlyph = layout->getSpeciesGlyph( - speciesGlyphAliasSpeciesGlyphIds[speciesGlyph->getId()]); - if (connectedSpeciesGlyph) { - speciesGlyphAliasSpeciesGlyphIds[speciesGlyph->getId()] = connectedSpeciesGlyph->getId(); - int stoichiometry = getStoichiometryAsInteger( - findSpeciesReference(document->getModel(), layout, referenceReactionGlyph, speciesGlyph)); - for (unsigned int stoichiometryIndex = 0; stoichiometryIndex < stoichiometry; stoichiometryIndex++) - createAliasSpeciesReferenceGlyph(reactionGlyph, speciesReferenceGlyph, - connectedSpeciesGlyph->getId(), stoichiometryIndex); - } - } - } - - return -1; -} - -SpeciesReferenceGlyph* createAliasSpeciesReferenceGlyph(ReactionGlyph* reactionGlyph, SpeciesReferenceGlyph* referenceSpeciesReferenceGlyph, const std::string& speciesGlyphId, unsigned int stoichiometryIndex) { - SpeciesReferenceGlyph* aliasSpeciesReferenceGlyph = createSpeciesReferenceGlyph(reactionGlyph, speciesGlyphId, stoichiometryIndex); - aliasSpeciesReferenceGlyph->setRole(referenceSpeciesReferenceGlyph->getRole()); - setSpeciesReferenceGlyphCurve(aliasSpeciesReferenceGlyph, referenceSpeciesReferenceGlyph); - return aliasSpeciesReferenceGlyph; -} - -void setTextGlyphs(Layout* layout) { - setCompartmentTextGlyphs(layout); - setSpeciesTextGlyphs(layout); - setReactionTextGlyphs(layout); -} - -void setCompartmentTextGlyphs(Layout* layout) { - for (unsigned int i = 0; i < layout->getNumCompartmentGlyphs(); i++) { - TextGlyph* textGlyph = createAssociatedTextGlyph(layout, layout->getCompartmentGlyph(i)); - setTextGlyphBoundingBox(textGlyph, layout->getCompartmentGlyph(i)); - } -} - -void setSpeciesTextGlyphs(Layout* layout) { - for (unsigned int i = 0; i < layout->getNumSpeciesGlyphs(); i++) { - TextGlyph* textGlyph = createAssociatedTextGlyph(layout, layout->getSpeciesGlyph(i)); - setTextGlyphBoundingBox(textGlyph, layout->getSpeciesGlyph(i)); - } -} - -void setReactionTextGlyphs(Layout* layout) { - for (unsigned int i = 0; i < layout->getNumReactionGlyphs(); i++) { - double padding = 5.0; - TextGlyph* textGlyph = createAssociatedTextGlyph(layout, layout->getReactionGlyph(i)); - setTextGlyphBoundingBox(textGlyph, layout->getReactionGlyph(i), padding); +bool isSetEmptySpeciesGlyph(Layout* layout, SpeciesReferenceGlyph* speciesReferenceGlyph) { + if (layout && speciesReferenceGlyph) { + SpeciesGlyph* speciesGlyph = layout->getSpeciesGlyph(speciesReferenceGlyph->getSpeciesGlyphId()); + return isEmptySpeciesGlyph(speciesGlyph); } -} - -CompartmentGlyph* createCompartmentGlyph(Layout* layout, const std::string& compartmentId, const std::vector>& userData) { - CompartmentGlyph* compartmentGlyph = layout->createCompartmentGlyph(); - compartmentGlyph->setId(getCompartmentGlyphId(layout, compartmentId)); - compartmentGlyph->setCompartmentId(compartmentId); - setGraphicalObjectBoundingBox(compartmentGlyph); - setGraphicalObjectUserData(compartmentGlyph, userData); - - return compartmentGlyph; -} - -SpeciesGlyph* createSpeciesGlyph(Layout* layout, const std::string& speciesId, const std::vector>& userData) { - SpeciesGlyph *speciesGlyph = layout->createSpeciesGlyph(); - speciesGlyph->setId(getSpeciesGlyphId(layout, speciesId)); - speciesGlyph->setSpeciesId(speciesId); - setGraphicalObjectBoundingBox(speciesGlyph); - setGraphicalObjectUserData(speciesGlyph, userData); - return speciesGlyph; + return false; } -SpeciesGlyph* createEmptySpeciesGlyph(Layout* layout, const std::string& reactionGlyphId) { - SpeciesGlyph *speciesGlyph = layout->createSpeciesGlyph(); - speciesGlyph->setId(reactionGlyphId + "_EmptySpeciesGlyph"); - setGraphicalObjectBoundingBox(speciesGlyph); - - return speciesGlyph; -} +const std::string getEmptySpeciesGlyphId(Layout* layout, SpeciesReferenceGlyph* speciesReferenceGlyph) { + if (isSetEmptySpeciesGlyph(layout, speciesReferenceGlyph)) + return layout->getSpeciesGlyph(speciesReferenceGlyph->getSpeciesGlyphId())->getId(); -ReactionGlyph* createReactionGlyph(Layout* layout, const std::string& reactionId, const std::vector>& userData) { - ReactionGlyph* reactionGlyph = layout->createReactionGlyph(); - reactionGlyph->setId(getReactionGlyphId(layout, reactionId)); - reactionGlyph->setReactionId(reactionId); - setReactionGlyphCurve(reactionGlyph); - setGraphicalObjectUserData(reactionGlyph, userData); - - return reactionGlyph; + return ""; } -SpeciesReferenceGlyph* createSpeciesReferenceGlyph(Layout* layout, ReactionGlyph* reactionGlyph, const std::string& speciesId, unsigned int stoichiometryIndex, const int maxNumConnectedEdges, const std::vector>& userData) { - SpeciesReferenceGlyph* speciesReferenceGlyph = reactionGlyph->createSpeciesReferenceGlyph(); - SpeciesGlyph* speciesGlyph = getSpeciesGlyph(layout, speciesId, maxNumConnectedEdges, userData); - speciesReferenceGlyph->setId(getSpeciesReferenceGlyphId(reactionGlyph, speciesGlyph->getId(), stoichiometryIndex)); - speciesReferenceGlyph->setSpeciesGlyphId(speciesGlyph->getId()); - setSpeciesReferenceGlyphCurve(speciesReferenceGlyph); - setGraphicalObjectUserData(speciesReferenceGlyph, userData); - - return speciesReferenceGlyph; -} +int setSpeciesGlyphIndexInReactionGlyph(Layout* layout, const std::string speciesId, ReactionGlyph* reactionGlyph, const unsigned int index) { + std::vector speciesGlyphs = getAssociatedSpeciesGlyphsWithSpeciesId(layout, speciesId); + std::vector speciesReferenceGlyphs = getSpeciesReferencesAssociatedWithSpecies(layout, reactionGlyph, speciesId); + int originalSpeciesGlyphIndex = getIndexOfConnectedSpeciesGlyph(speciesReferenceGlyphs, speciesGlyphs); + if (originalSpeciesGlyphIndex != -1 && originalSpeciesGlyphIndex != index && index < speciesGlyphs.size()) { + SpeciesGlyph* originalSpeciesGlyph = speciesGlyphs.at(originalSpeciesGlyphIndex); + SpeciesGlyph* newSpeciesGlyph = speciesGlyphs.at(index); + for (unsigned int i = 0; i < speciesReferenceGlyphs.size(); i++) { + SpeciesReferenceGlyph* speciesReferenceGlyph = speciesReferenceGlyphs.at(i); + speciesReferenceGlyph->setId(getIdOfSpeciesReferenceGlyphConnectedToNewSpeciesGlyph(speciesReferenceGlyph->getId(), originalSpeciesGlyph->getId(), newSpeciesGlyph->getId())); + speciesReferenceGlyph->setSpeciesGlyphId(newSpeciesGlyph->getId()); + } + if (!getSpeciesReferencesAssociatedWithSpeciesGlyph(layout, originalSpeciesGlyph->getId()).size()) { + user_data_freeUserData(originalSpeciesGlyph); + layout->removeSpeciesGlyph(originalSpeciesGlyph->getId()); + } -SpeciesReferenceGlyph* createSpeciesReferenceGlyph(ReactionGlyph* reactionGlyph, const std::string& speciesGlyphId, unsigned int stoichiometryIndex) { - SpeciesReferenceGlyph* speciesReferenceGlyph = reactionGlyph->createSpeciesReferenceGlyph(); - speciesReferenceGlyph->setId(getSpeciesReferenceGlyphId(reactionGlyph, speciesGlyphId, stoichiometryIndex)); - speciesReferenceGlyph->setSpeciesGlyphId(speciesGlyphId); + return 0; + } - return speciesReferenceGlyph; + return -1; } CompartmentGlyph* getCompartmentGlyphOfReactionGlyph(Model* model, Layout* layout, ReactionGlyph* reactionGlyph) { @@ -948,14 +103,7 @@ CompartmentGlyph* getCompartmentGlyphOfReactionGlyph(Model* model, Layout* layou return compartmentGlyphs.at(0); } - return getDefaultCompartmentGlyph(layout); -} - -CompartmentGlyph* getDefaultCompartmentGlyph(Layout* layout) { - if (layout->getNumCompartmentGlyphs() == 1 && layout->getCompartmentGlyph(0)->getCompartmentId() == "default_compartment") - return layout->getCompartmentGlyph(0); - - return NULL; + return defaults_getDefaultCompartmentGlyph(layout); } const int getNumSpeciesReferencesAssociatedWithSpecies(Reaction* reaction, const std::string& speciesId) { @@ -1068,46 +216,16 @@ TextGlyph* createAssociatedTextGlyph(Layout* layout, GraphicalObject* graphicalO return textGlyph; } -void setGraphicalObjectUserData(GraphicalObject* graphicalObject, const std::vector>& userData) { - for (unsigned int i = 0; i < userData.size(); i++) { - if (userData.at(i).find("id") != userData.at(i).end() && userData.at(i).at("id") == graphicalObject->getId()) { - for (auto it = userData.at(i).begin(); it != userData.at(i).end(); it++) - setUserData(graphicalObject, it->first, it->second); - break; - } - } -} - -void setGraphicalObjectBoundingBox(GraphicalObject* graphicalObject) { - if (!graphicalObject->getBoundingBox()->isSetId()) - graphicalObject->getBoundingBox()->setId(graphicalObject->getId() + "_bb"); -} - void setReactionGlyphCurve(ReactionGlyph* reactionGlyph) { if (!reactionGlyph->isSetCurve()) { double x = reactionGlyph->getBoundingBox()->x(); double y = reactionGlyph->getBoundingBox()->y(); double width = reactionGlyph->getBoundingBox()->width(); double height = reactionGlyph->getBoundingBox()->height(); - setCurveCubicBezier(reactionGlyph->getCurve(), x + 0.5 * width, y + 0.5 * height); - } -} - -void setSpeciesReferenceGlyphCurve(SpeciesReferenceGlyph* speciesReferenceGlyph, SpeciesReferenceGlyph* referenceSpeciesReferenceGlyph) { - if (referenceSpeciesReferenceGlyph->isSetCurve()) { - double padding = getAliasReactionGlyphPadding(); - Curve* referenceCurve = referenceSpeciesReferenceGlyph->getCurve(); - Curve* curve = speciesReferenceGlyph->getCurve(); - for (unsigned int i = 0; i < referenceCurve->getNumCurveSegments(); i++) - addCurveSegment(curve, referenceCurve->getCurveSegment(i), getAliasReactionGlyphPadding()); + set_layout_features_setCurveCubicBezier(reactionGlyph->getCurve(), x + 0.5 * width, y + 0.5 * height); } } -void setSpeciesReferenceGlyphCurve(SpeciesReferenceGlyph* speciesReferenceGlyph) { - if (!speciesReferenceGlyph->isSetCurve()) - setCurveCubicBezier(speciesReferenceGlyph->getCurve()); -} - int removeReactionGlyphCurve(ReactionGlyph* reactionGlyph) { double x = getPositionX(reactionGlyph); double y = getPositionY(reactionGlyph); @@ -1130,40 +248,6 @@ void setTextGlyphBoundingBox(TextGlyph* textGlyph, GraphicalObject* graphicalObj textGlyph->getBoundingBox()->setHeight(graphicalObject->getBoundingBox()->height()); } -void addCurveSegment(Curve* curve, LineSegment* referenceLineSegment, const double& padding) { - if (isCubicBezier(referenceLineSegment)) { - CubicBezier* referenceCubicBezier = static_cast(referenceLineSegment); - CubicBezier* cubicBezier = curve->createCubicBezier(); - cubicBezier->getStart()->setX(referenceCubicBezier->getStart()->x() + padding); - cubicBezier->getStart()->setY(referenceCubicBezier->getStart()->y() + padding); - cubicBezier->getBasePoint1()->setX(referenceCubicBezier->getBasePoint1()->x() + padding); - cubicBezier->getBasePoint1()->setY(referenceCubicBezier->getBasePoint1()->y() + padding); - cubicBezier->getBasePoint2()->setX(referenceCubicBezier->getBasePoint2()->x() + padding); - cubicBezier->getBasePoint2()->setY(referenceCubicBezier->getBasePoint2()->y() + padding); - cubicBezier->getEnd()->setX(referenceCubicBezier->getEnd()->x() + padding); - cubicBezier->getEnd()->setY(referenceCubicBezier->getEnd()->y() + padding); - } - else { - LineSegment* lineSegment = curve->createLineSegment(); - lineSegment->getStart()->setX(referenceLineSegment->getStart()->x() + padding); - lineSegment->getStart()->setY(referenceLineSegment->getStart()->y() + padding); - lineSegment->getEnd()->setX(referenceLineSegment->getEnd()->x() + padding); - lineSegment->getEnd()->setY(referenceLineSegment->getEnd()->y() + padding); - } -} - -void setCurveCubicBezier(Curve* curve, const double& x, const double& y) { - CubicBezier* cubicBezier = curve->createCubicBezier(); - cubicBezier->getStart()->setX(x); - cubicBezier->getStart()->setY(y); - cubicBezier->getBasePoint1()->setX(x); - cubicBezier->getBasePoint1()->setY(y); - cubicBezier->getBasePoint2()->setX(x); - cubicBezier->getBasePoint2()->setY(y); - cubicBezier->getEnd()->setX(x); - cubicBezier->getEnd()->setY(y); -} - Compartment* findCompartmentGlyphCompartment(Model* model, CompartmentGlyph* compartmentGlyph) { return model->getCompartment(compartmentGlyph->getCompartmentId()); } @@ -1173,7 +257,7 @@ Compartment* findSpeciesGlyphCompartment(Model* model, SpeciesGlyph* speciesGlyp if (species) return model->getCompartment(species->getCompartment()); else - return model->getCompartment(getUserData(speciesGlyph, "compartment")); + return model->getCompartment(user_data_getUserData(speciesGlyph, "compartment")); } Species* findSpeciesGlyphSpecies(Model* model, SpeciesGlyph* speciesGlyph) { @@ -1393,87 +477,6 @@ const std::string getTextGlyphUniqueId(Layout* layout, GraphicalObject* graphica return textGlyphUniqueId; } -const std::string getCompartmentGlyphId(Layout* layout, const std::string compartmentId) { - std::string compartmentGlyphId = ""; - int compartmentGlyphIndex = 1; - std::vector compartmentGlyphs = getAssociatedCompartmentGlyphsWithCompartmentId(layout, compartmentId); - while (true) { - compartmentGlyphId = compartmentId + "_Glyph_" + std::to_string(compartmentGlyphIndex++); - bool isUniqueId = true; - for (unsigned int i = 0; i < compartmentGlyphs.size(); i++) { - if (compartmentGlyphId == compartmentGlyphs.at(i)->getId()) { - isUniqueId = false; - break; - } - } - if (isUniqueId) - break; - } - - return compartmentGlyphId; -} - -const std::string getSpeciesGlyphId(Layout* layout, const std::string speciesId) { - std::string speciesGlyphId = ""; - int speciesGlyphIndex = 1; - std::vector speciesGlyphs = getAssociatedSpeciesGlyphsWithSpeciesId(layout, speciesId); - while (true) { - speciesGlyphId = speciesId + "_Glyph_" + std::to_string(speciesGlyphIndex++); - bool isUniqueId = true; - for (unsigned int i = 0; i < speciesGlyphs.size(); i++) { - if (speciesGlyphId == speciesGlyphs.at(i)->getId()) { - isUniqueId = false; - break; - } - } - if (isUniqueId) - break; - } - - return speciesGlyphId; -} - -const std::string getReactionGlyphId(Layout* layout, const std::string reactionId) { - std::string reactionGlyphId = ""; - int reactionGlyphIndex = 1; - std::vector reactionGlyphs = getAssociatedReactionGlyphsWithReactionId(layout, reactionId); - while (true) { - reactionGlyphId = reactionId + "_Glyph_" + std::to_string(reactionGlyphIndex++); - bool isUniqueId = true; - for (unsigned int i = 0; i < reactionGlyphs.size(); i++) { - if (reactionGlyphId == reactionGlyphs.at(i)->getId()) { - isUniqueId = false; - break; - } - } - if (isUniqueId) - break; - } - - return reactionGlyphId; -} - -const std::string getSpeciesReferenceGlyphId(ReactionGlyph* reactionGlyph, const std::string speciesGlyphId, unsigned int stoichiometryIndex) { - std::string speciesReferenceGlyphId = ""; - int speciesReferenceGlyphIndex = 1; - std::vector speciesReferenceGlyphs = getSpeciesReferenceGlyphs(reactionGlyph); - std::string stoichiometryPhrase = "_Stoichiometry_" + std::to_string(stoichiometryIndex + 1); - while (true) { - speciesReferenceGlyphId = speciesGlyphId + "_" + reactionGlyph->getId() + stoichiometryPhrase + "_Glyph_" + std::to_string(speciesReferenceGlyphIndex++); - bool isUniqueId = true; - for (unsigned int i = 0; i < speciesReferenceGlyphs.size(); i++) { - if (speciesReferenceGlyphId == speciesReferenceGlyphs.at(i)->getId()) { - isUniqueId = false; - break; - } - } - if (isUniqueId) - break; - } - - return speciesReferenceGlyphId; -} - const std::string getIdOfSpeciesReferenceGlyphConnectedToNewSpeciesGlyph(std::string speciesReferenceGlyphId, const std::string& originalSpeciesGlyphId, const std::string& newSpeciesGlyphId) { std::string::size_type pos = speciesReferenceGlyphId.find(originalSpeciesGlyphId); if (pos != std::string::npos) @@ -1578,379 +581,15 @@ int setCurveMiddlePositionY(Curve* curve, const double& y) { return -1; } -void alignGraphicalObjects(Layout* layout, std::vector graphicalObjects, const std::string& alignment, const bool ignoreLockedNodes) { - if (isValidAlignment(alignment, layout)) { - if (stringCompare(alignment, "top")) - alignGraphicalObjectsToTop(layout, graphicalObjects, ignoreLockedNodes); - else if (stringCompare(alignment, "vCenter")) - alignGraphicalObjectsToVerticalCenter(layout, graphicalObjects, ignoreLockedNodes); - else if (stringCompare(alignment, "bottom")) - alignGraphicalObjectsToBottom(layout, graphicalObjects, ignoreLockedNodes); - else if (stringCompare(alignment, "left")) - alignGraphicalObjectsToLeft(layout, graphicalObjects, ignoreLockedNodes); - else if (stringCompare(alignment, "hCenter")) - alignGraphicalObjectsToHorizontalCenter(layout, graphicalObjects, ignoreLockedNodes); - else if (stringCompare(alignment, "right")) - alignGraphicalObjectsToRight(layout, graphicalObjects, ignoreLockedNodes); - else if (stringCompare(alignment, "circular") || stringCompare(alignment, "circle")) - alignGraphicalObjectsCircularly(layout, graphicalObjects, ignoreLockedNodes); - } -} - -void alignGraphicalObjectsToTop(Layout* layout, std::vector graphicalObjects, const bool ignoreLockedNodes) { - try { - double minY = getTopAlignmentPosition(graphicalObjects, ignoreLockedNodes); - for (unsigned int i = 0; i < graphicalObjects.size(); i++) - setPositionY(layout, graphicalObjects.at(i), minY); - } - catch (const std::invalid_argument& e) { - addErrorToLog(layout, e.what()); - } -} - -const double getTopAlignmentPosition(std::vector graphicalObjects, const bool ignoreLockedNodes) { - if (ignoreLockedNodes) - return getMinPositionY(graphicalObjects); - std::vector lockedGraphicalObjects = getLockedGraphicalObjects(graphicalObjects); - if (lockedGraphicalObjects.size() == 0) - return getMinPositionY(graphicalObjects); - else if (lockedGraphicalObjects.size() == 1) - return lockedGraphicalObjects.at(0)->getBoundingBox()->y(); - else - throw std::invalid_argument("error: Multiple graphical objects in your align list are locked, so the alignment cannot be applied. Use the ignoreLockedNodes option to ignore locked nodes.\n"); -} - -void alignGraphicalObjectsToHorizontalCenter(Layout* layout, std::vector graphicalObjects, const bool ignoreLockedNodes) { - try { - double centerX = getHorizontalCenterAlignmentPosition(graphicalObjects, ignoreLockedNodes); - for (unsigned int i = 0; i < graphicalObjects.size(); i++) - setPositionX(layout, graphicalObjects.at(i), centerX); - } - catch (const std::invalid_argument& e) { - addErrorToLog(layout, e.what()); - } -} - -const double getHorizontalCenterAlignmentPosition(std::vector graphicalObjects, const bool ignoreLockedNodes) { - if (ignoreLockedNodes) - return 0.5 * (getMinPositionX(graphicalObjects) + getMaxPositionX(graphicalObjects)); - std::vector lockedGraphicalObjects = getLockedGraphicalObjects(graphicalObjects); - if (lockedGraphicalObjects.size() == 0) - return 0.5 * (getMinPositionX(graphicalObjects) + getMaxPositionX(graphicalObjects)); - else if (lockedGraphicalObjects.size() == 1) - return lockedGraphicalObjects.at(0)->getBoundingBox()->x(); - else - throw std::invalid_argument("error: Multiple graphical objects in your align list are locked, so the alignment cannot be applied. Use the ignoreLockedNodes option to ignore locked nodes.\n"); -} - -void alignGraphicalObjectsToBottom(Layout* layout, std::vector graphicalObjects, const bool ignoreLockedNodes) { - try { - double maxY = getBottomAlignmentPosition(graphicalObjects, ignoreLockedNodes); - for (unsigned int i = 0; i < graphicalObjects.size(); i++) - setPositionY(layout, graphicalObjects.at(i), maxY); - } - catch (const std::invalid_argument& e) { - addErrorToLog(layout, e.what()); - } -} - -const double getBottomAlignmentPosition(std::vector graphicalObjects, const bool ignoreLockedNodes) { - if (ignoreLockedNodes) - return getMaxPositionY(graphicalObjects); - std::vector lockedGraphicalObjects = getLockedGraphicalObjects(graphicalObjects); - if (lockedGraphicalObjects.size() == 0) - return getMaxPositionY(graphicalObjects); - else if (lockedGraphicalObjects.size() == 1) - return lockedGraphicalObjects.at(0)->getBoundingBox()->y(); - else - throw std::invalid_argument("error: Multiple graphical objects in your align list are locked, so the alignment cannot be applied. Use the ignoreLockedNodes option to ignore locked nodes.\n"); -} - -void alignGraphicalObjectsToLeft(Layout* layout, std::vector graphicalObjects, const bool ignoreLockedNodes) { - try { - double minX = getLeftAlignmentPosition(graphicalObjects, ignoreLockedNodes); - for (unsigned int i = 0; i < graphicalObjects.size(); i++) - setPositionX(layout, graphicalObjects.at(i), minX); - } - catch (const std::invalid_argument& e) { - addErrorToLog(layout, e.what()); - } -} - -const double getLeftAlignmentPosition(std::vector graphicalObjects, const bool ignoreLockedNodes) { - if (ignoreLockedNodes) - return getMinPositionX(graphicalObjects); - std::vector lockedGraphicalObjects = getLockedGraphicalObjects(graphicalObjects); - if (lockedGraphicalObjects.size() == 0) - return getMinPositionX(graphicalObjects); - else if (lockedGraphicalObjects.size() == 1) - return lockedGraphicalObjects.at(0)->getBoundingBox()->x(); - else - throw std::invalid_argument("error: Multiple graphical objects in your align list are locked, so the alignment cannot be applied. Use the ignoreLockedNodes option to ignore locked nodes.\n"); -} - -void alignGraphicalObjectsToVerticalCenter(Layout* layout, std::vector graphicalObjects, const bool ignoreLockedNodes) { - try { - double centerY = getVerticalCenterAlignmentPosition(graphicalObjects, ignoreLockedNodes); - for (unsigned int i = 0; i < graphicalObjects.size(); i++) - setPositionY(layout, graphicalObjects.at(i), centerY); - } - catch (const std::invalid_argument& e) { - addErrorToLog(layout, e.what()); - } -} - -const double getVerticalCenterAlignmentPosition(std::vector graphicalObjects, const bool ignoreLockedNodes) { - if (ignoreLockedNodes) - return 0.5 * (getMinPositionY(graphicalObjects) + getMaxPositionY(graphicalObjects)); - std::vector lockedGraphicalObjects = getLockedGraphicalObjects(graphicalObjects); - if (lockedGraphicalObjects.size() == 0) - return 0.5 * (getMinPositionY(graphicalObjects) + getMaxPositionY(graphicalObjects)); - else if (lockedGraphicalObjects.size() == 1) - return lockedGraphicalObjects.at(0)->getBoundingBox()->y(); - else - throw std::invalid_argument("error: Multiple graphical objects in your align list are locked, so the alignment cannot be applied. Use the ignoreLockedNodes option to ignore locked nodes.\n"); -} - -void alignGraphicalObjectsToRight(Layout* layout, std::vector graphicalObjects, const bool ignoreLockedNodes) { - try { - double maxX = getRightAlignmentPosition(graphicalObjects, ignoreLockedNodes); - for (unsigned int i = 0; i < graphicalObjects.size(); i++) - setPositionX(layout, graphicalObjects.at(i), maxX); - } - catch (const std::invalid_argument& e) { - addErrorToLog(layout, e.what()); - } -} - -const double getRightAlignmentPosition(std::vector graphicalObjects, const bool ignoreLockedNodes) { - if (ignoreLockedNodes) - return getMaxPositionX(graphicalObjects); - std::vector lockedGraphicalObjects = getLockedGraphicalObjects(graphicalObjects); - if (lockedGraphicalObjects.size() == 0) - return getMaxPositionX(graphicalObjects); - else if (lockedGraphicalObjects.size() == 1) - return lockedGraphicalObjects.at(0)->getBoundingBox()->x(); - else - throw std::invalid_argument("error: Multiple graphical objects in your align list are locked, so the alignment cannot be applied. Use the ignoreLockedNodes option to ignore locked nodes.\n"); -} - -void alignGraphicalObjectsCircularly(Layout* layout, std::vector graphicalObjects, const bool ignoreLockedNodes) { - double radius = graphicalObjects.size() * 50.0; - double angle = 2 * M_PI / graphicalObjects.size(); - double centerX = std::max(radius, 0.5 * (getMinCenterX(graphicalObjects) + getMaxCenterX(graphicalObjects))); - double centerY = std::max(radius, 0.5 * (getMinCenterY(graphicalObjects) + getMaxCenterY(graphicalObjects))); - for (unsigned int i = 0; i < graphicalObjects.size(); i++) { - setPositionX(layout, graphicalObjects.at(i), centerX + radius * cos(i * angle) - 0.5 * graphicalObjects.at(i)->getBoundingBox()->width()); - setPositionY(layout, graphicalObjects.at(i), centerY + radius * sin(i * angle) - 0.5 * graphicalObjects.at(i)->getBoundingBox()->height()); - } -} - -void distributeGraphicalObjects(Layout* layout, std::vector graphicalObjects, const std::string& direction, const double& spacing) { - if (isValidDistributionDirection(direction, layout)) { - if (stringCompare(direction, "horizontal")) - distributeGraphicalObjectsHorizontally(layout, graphicalObjects, spacing); - else if (stringCompare(direction, "vertical")) - distributeGraphicalObjectsVertically(layout, graphicalObjects, spacing); - } -} - -void distributeGraphicalObjectsHorizontally(Layout* layout, std::vector graphicalObjects, const double& spacing) { - if (graphicalObjects.size() < 2) - return; - double minX = getMinPositionX(graphicalObjects); - double maxX = getMaxPositionX(graphicalObjects); - double minY = getMinPositionY(graphicalObjects); - double maxY = getMaxPositionY(graphicalObjects); - double distance = findDistributionDistance(minX, maxX, graphicalObjects.size(), spacing); - if (graphicalObjects.size() % 2 == 0) { - for (unsigned int i = 0; i < graphicalObjects.size(); i++) { - setPositionX(layout, graphicalObjects.at(i), minX + i * distance); - setPositionY(layout, graphicalObjects.at(i), 0.5 * (minY + maxY)); - } - } - else { - for (unsigned int i = 0; i < graphicalObjects.size(); i++) { - setPositionX(layout, graphicalObjects.at(i), - 0.5 * (minX + maxX) + (i - 0.5 * (graphicalObjects.size() - 1)) * distance); - setPositionY(layout, graphicalObjects.at(i), 0.5 * (minY + maxY)); - } - } -} - -void distributeGraphicalObjectsVertically(Layout* layout, std::vector graphicalObjects, const double& spacing) { - if (graphicalObjects.size() < 2) - return; - double minX = getMinPositionX(graphicalObjects); - double maxX = getMaxPositionX(graphicalObjects); - double minY = getMinPositionY(graphicalObjects); - double maxY = getMaxPositionY(graphicalObjects); - double distance = findDistributionDistance(minY, maxY, graphicalObjects.size(), spacing); - - if (graphicalObjects.size() % 2 == 0) { - for (unsigned int i = 0; i < graphicalObjects.size(); i++) { - setPositionX(layout, graphicalObjects.at(i), 0.5 * (minX + maxX)); - setPositionY(layout, graphicalObjects.at(i), minY + i * distance); - } - } - else { - for (unsigned int i = 0; i < graphicalObjects.size(); i++) { - setPositionX(layout, graphicalObjects.at(i), 0.5 * (minX + maxX)); - setPositionY(layout, graphicalObjects.at(i), - 0.5 * (minY + maxY) + (i - 0.5 * (graphicalObjects.size() - 1)) * distance); - } - } -} - -const double findDistributionDistance(const double& minPosition, const double& maxPosition, const unsigned int& numGraphicalObjects, const double& spacing) { - double distance = 0; - if (spacing > 0) - distance = spacing; - else - distance = (maxPosition - minPosition) / (numGraphicalObjects - 1); - - return distance; -} - -std::vector getSortedNodeIdsVector(std::set > nodeIds) { - std::vector sortedNodeIdsVector; - for (unsigned int nodeIdIndex = 0; nodeIdIndex < nodeIds.size(); nodeIdIndex++) { - for (std::set>::const_iterator nodeIt = nodeIds.cbegin(); nodeIt != nodeIds.cend(); nodeIt++) { - if (nodeIt->second == nodeIdIndex) { - sortedNodeIdsVector.push_back(nodeIt->first); - break; - } - } - } - - return sortedNodeIdsVector; -} - -const double getMinPositionX(std::vector graphicalObjects) { - if (graphicalObjects.size()) { - double minX = INT_MAX; - for (unsigned int i = 0; i < graphicalObjects.size(); i++) - if (graphicalObjects.at(i)->getBoundingBox()->x() < minX) - minX = graphicalObjects.at(i)->getBoundingBox()->x(); - - return minX; - } - - return 0.0; -} - -const double getMinPositionY(std::vector graphicalObjects) { - if (graphicalObjects.size()) { - double minY = INT_MAX; - for (unsigned int i = 0; i < graphicalObjects.size(); i++) - if (graphicalObjects.at(i)->getBoundingBox()->y() < minY) - minY = graphicalObjects.at(i)->getBoundingBox()->y(); - - return minY; - } - - return 0.0; -} - -const double getMaxPositionX(std::vector graphicalObjects) { - if (graphicalObjects.size()) { - double maxX = INT_MIN; - for (unsigned int i = 0; i < graphicalObjects.size(); i++) - if (graphicalObjects.at(i)->getBoundingBox()->x() > maxX) - maxX = graphicalObjects.at(i)->getBoundingBox()->x(); - - return maxX; - } - - return 0.0; -} - -const double getMaxPositionY(std::vector graphicalObjects) { - if (graphicalObjects.size()) { - double maxY = INT_MIN; - for (unsigned int i = 0; i < graphicalObjects.size(); i++) - if (graphicalObjects.at(i)->getBoundingBox()->y() > maxY) - maxY = graphicalObjects.at(i)->getBoundingBox()->y(); - - return maxY; - } - - return 0.0; -} - -const double getMinCenterX(std::vector graphicalObjects) { - if (graphicalObjects.size()) { - double minX = INT_MAX; - for (unsigned int i = 0; i < graphicalObjects.size(); i++) - if (graphicalObjects.at(i)->getBoundingBox()->x() + 0.5 * graphicalObjects.at(i)->getBoundingBox()->width() < minX) - minX = graphicalObjects.at(i)->getBoundingBox()->x() + 0.5 * graphicalObjects.at(i)->getBoundingBox()->width(); - - return minX; - } - - return 0.0; -} - -const double getMinCenterY(std::vector graphicalObjects) { - if (graphicalObjects.size()) { - double minY = INT_MAX; - for (unsigned int i = 0; i < graphicalObjects.size(); i++) - if (graphicalObjects.at(i)->getBoundingBox()->y() + 0.5 * graphicalObjects.at(i)->getBoundingBox()->height() < minY) - minY = graphicalObjects.at(i)->getBoundingBox()->y() + 0.5 * graphicalObjects.at(i)->getBoundingBox()->height(); - - return minY; - } - - return 0.0; -} - -const double getMaxCenterX(std::vector graphicalObjects) { - if (graphicalObjects.size()) { - double maxX = INT_MIN; - for (unsigned int i = 0; i < graphicalObjects.size(); i++) - if (graphicalObjects.at(i)->getBoundingBox()->x() + 0.5 * graphicalObjects.at(i)->getBoundingBox()->width() > maxX) - maxX = graphicalObjects.at(i)->getBoundingBox()->x() + 0.5 * graphicalObjects.at(i)->getBoundingBox()->width(); - - return maxX; - } - - return 0.0; -} - -const double getMaxCenterY(std::vector graphicalObjects) { - if (graphicalObjects.size()) { - double maxY = INT_MIN; - for (unsigned int i = 0; i < graphicalObjects.size(); i++) - if (graphicalObjects.at(i)->getBoundingBox()->y() + 0.5 * graphicalObjects.at(i)->getBoundingBox()->height() > maxY) - maxY = graphicalObjects.at(i)->getBoundingBox()->y() + 0.5 * graphicalObjects.at(i)->getBoundingBox()->height(); - - return maxY; - } - - return 0.0; -} - -const double getDefaultAutoLayoutPadding() { - return 30.0; -} - -const double getAliasSpeciesGlyphPadding() { - return 30.0; -} - -const double getAliasReactionGlyphPadding() { - return 30.0; -} - const bool isValidLayoutDimensionWidthValue(const double& width, SBase* sBase) { - if (isValidDimensionValue(width, sBase) && width > 6 * getDefaultAutoLayoutPadding()) + if (isValidDimensionValue(width, sBase) && width > 6 * defaults_getDefaultAutoLayoutPadding()) return true; return false; } const bool isValidLayoutDimensionHeightValue(const double& height, SBase* sBase) { - if (isValidDimensionValue(height, sBase) && height > 6 * getDefaultAutoLayoutPadding()) + if (isValidDimensionValue(height, sBase) && height > 6 * defaults_getDefaultAutoLayoutPadding()) return true; return false; @@ -1960,7 +599,7 @@ const bool isValidRoleValue(const std::string& role, SBase* sBase) { if (isValueValid(role, getValidRoleValues())) return true; - addErrorToLog(sBase, createErrorMessage(role, getValidRoleValues())); + error_log_addErrorToLog(sBase, error_log_createErrorMessage(role, getValidRoleValues())); return false; } @@ -2016,7 +655,7 @@ const bool isValidDimensionValue(const double& dimensionValue, SBase* sBase) { if (isValidDoubleValue(dimensionValue, sBase) && dimensionValue > 0.000) return true; - addErrorToLog(sBase, "A dimension value must be greater than 0"); + error_log_addErrorToLog(sBase, "A dimension value must be greater than 0"); return false; } @@ -2024,23 +663,7 @@ const bool isValidDoubleValue(const double& doubleValue, SBase* sBase) { if (!std::isnan(doubleValue) && !std::isinf(doubleValue)) return true; - addErrorToLog(sBase, "A double value must be a valid number"); - return false; -} - -const bool isValidAlignment(const std::string& alignment, SBase* sBase) { - if (isValueValid(alignment, getValidAlignmentValues())) - return true; - - addErrorToLog(sBase, createErrorMessage(alignment, getValidAlignmentValues())); - return false; -} - -const bool isValidDistributionDirection(const std::string& direction, SBase* sBase) { - if (isValueValid(direction, getValidDistributionDirectionValues())) - return true; - - addErrorToLog(sBase, createErrorMessage(direction, getValidDistributionDirectionValues())); + error_log_addErrorToLog(sBase, "A double value must be a valid number"); return false; } @@ -2058,25 +681,4 @@ std::vector getValidRoleValues() { return roleValues; } -std::vector getValidAlignmentValues() { - std::vector alignmentValues; - alignmentValues.push_back("top"); - alignmentValues.push_back("vCenter"); - alignmentValues.push_back("bottom"); - alignmentValues.push_back("left"); - alignmentValues.push_back("hCenter"); - alignmentValues.push_back("right"); - alignmentValues.push_back("circular"); - - return alignmentValues; -} - -std::vector getValidDistributionDirectionValues() { - std::vector distributionDirectionValues; - distributionDirectionValues.push_back("horizontal"); - distributionDirectionValues.push_back("vertical"); - - return distributionDirectionValues; -} - } diff --git a/src/libsbmlnetwork_layout_helpers.h b/src/libsbmlnetwork_layout_helpers.h index b548ea1..d6879db 100755 --- a/src/libsbmlnetwork_layout_helpers.h +++ b/src/libsbmlnetwork_layout_helpers.h @@ -22,180 +22,12 @@ LayoutModelPlugin* getLayoutModelPlugin(SBasePlugin* layoutBase); void enableLayoutPlugin(SBMLDocument* document); -std::string getErrorLog(Layout* layout); - -std::string getErrorLog(GraphicalObject* graphicalObject); - -std::string getErrorLog(BoundingBox* boundingBox); - -std::string getErrorLog(Curve* curve); - -std::string getErrorLog(LineSegment* lineSegment); - -void clearErrorLog(Layout* layout); - -void clearErrorLog(GraphicalObject* graphicalObject); - -void clearErrorLog(BoundingBox* boundingBox); - -void clearErrorLog(Curve* curve); - -void clearErrorLog(LineSegment* lineSegment); - -void freeUserData(Layout* layout); - -std::vector> getUserData(Layout* layout); - -void setUserData(GraphicalObject* graphicalObject, const std::string& key, const std::string& value); - -void setPositionData(GraphicalObject* graphicalObject); - -void unsetPositionData(GraphicalObject* graphicalObject); - -void setPositionData(SpeciesReferenceGlyph* speciesReferenceGlyph); - -void unsetPositionData(SpeciesReferenceGlyph* speciesReferenceGlyph); - -void setDefaultLayoutId(Layout* layout); - -const std::string getDefaultLayoutId(); - -void setDefaultLayoutDimensions(Layout* layout); - -const double getSpeciesDefaultWidth(); - -const double getSpeciesDefaultHeight(); - -const double getEmptySpeciesDefaultRadius(); - -const double getReactionDefaultWidth(); - -const double getReactionDefaultHeight(); - -void lockGraphicalObjects(Layout* layout, std::set > lockedNodesSet, const bool resetLockedElements); - -void lockCompartmentGlyphs(Layout* layout, const bool resetLockedElements); - -void lockSpeciesGlyphs(Layout* layout, std::set > lockedNodesSet, const bool resetLockedElements); - -void lockReactionGlyphs(Layout* layout, std::set > lockedNodesSet, const bool resetLockedElements); - -void lockGraphicalObject(GraphicalObject* graphicalObject); - -void unlockGraphicalObject(GraphicalObject* graphicalObject); - -std::vector getLockedGraphicalObjects(std::vector graphicalObjects); - -void fixGraphicalObjectWidth(GraphicalObject* graphicalObject); - -void unfixGraphicalObjectWidth(GraphicalObject* graphicalObject); - -void fixGraphicalObjectHeight(GraphicalObject* graphicalObject); - -void unfixGraphicalObjectHeight(GraphicalObject* graphicalObject); - -void clearGraphicalObjects(Layout* layout); - -void clearCompartmentGlyphs(Layout* layout); - -void clearSpeciesGlyphs(Layout* layout); - -void clearReactionGlyphs(Layout* layout); - -void clearReactionGlyphSpeciesReferenceGlyphs(ReactionGlyph* reactionGlyph); - -void setCompartmentGlyphs(Model* model, Layout* layout, const std::vector>& userData = {}); - -void setReactionGlyphs(Model* model, Layout* layout, const int maxNumConnectedEdges, const std::vector>& userData = {}); - -void setReactantGlyphs(Layout* layout, Reaction* reaction, ReactionGlyph* reactionGlyph, const int maxNumConnectedEdges, const std::vector>& userData); - -void setProductGlyphs(Layout* layout, Reaction* reaction, ReactionGlyph* reactionGlyph, const int maxNumConnectedEdges, const std::vector>& userData); - -void setModifierGlyphs(Layout* layout, Reaction* reaction, ReactionGlyph* reactionGlyph, const int maxNumConnectedEdges, const std::vector>& userData); - -void setEmptySpeciesReferenceGlyphs(Model* model, Layout* layout, ReactionGlyph* reactionGlyph, const std::vector>& userData = {}); - -SpeciesReferenceGlyph* createEmptySpeciesReferenceGlyph(Model* model, Layout* layout, ReactionGlyph* reactionGlyph); - -SpeciesGlyph* createEmptySpeciesGlyph(Model* model, Layout* layout, ReactionGlyph* reactionGlyph); - -SpeciesGlyph* createEmptySpeciesGlyph(ReactionGlyph* reactionGlyph); - -SpeciesReferenceGlyph* createEmptySpeciesReferenceGlyph(Layout* layout, ReactionGlyph* reactionGlyph, SpeciesGlyph* EmptySpeciesGlyph); - -void setAliasSpeciesGlyphs(Layout* layout, const int maxNumConnectedEdges, const std::vector>& userData = {}); - bool isSetEmptySpeciesGlyph(Layout* layout, SpeciesReferenceGlyph* speciesReferenceGlyph); const std::string getEmptySpeciesGlyphId(Layout* layout, SpeciesReferenceGlyph* speciesReferenceGlyph); -int createAliasSpeciesGlyph(Layout* layout, const std::string speciesId, ReactionGlyph* reactionGlyph); - -SpeciesGlyph* createAliasSpeciesGlyph(Layout* layout, SpeciesGlyph* speciesGlyph); - -SpeciesGlyph* createAliasSpeciesGlyph(Layout* layout, const std::string& speciesId, std::vector speciesGlyphReferences); - -SpeciesGlyph* getSpeciesGlyph(Layout* layout, const std::string& speciesId, const int maxNumConnectedEdges, const std::vector>& userData); - int setSpeciesGlyphIndexInReactionGlyph(Layout* layout, const std::string speciesId, ReactionGlyph* reactionGlyph, const unsigned int index); -int makeSpeciesGlyphsVisible(Model* model, Layout* layout, std::set > species, bool visible = true); - -int makeSpeciesGlyphVisible(ReactionGlyph* reactionGlyph, const std::string speciesId, bool visible = true); - -int hideSpeciesGlyph(SBase* sBase, const std::string speciesId); - -int unHideSpeciesGlyph(SBase* sBase, const std::string speciesId); - -const bool isSpeciesGlyphHidden(Layout* layout, ReactionGlyph* reactionGlyph, const std::string speciesId); - -const bool canHaveAlias(Layout* layout, std::vector connectedSpeciesGlyphReferencesOfReactionGlyph); - -void setAliasGraphicalObjectPosition(GraphicalObject* aliasGraphicalObject, GraphicalObject* graphicalObject, const double& padding = 0.0); - -void setAliasSpeciesGlyphDimensions(SpeciesGlyph* aliasSpeciesGlyph, GraphicalObject* graphicalObject); - -void setAliasSpeciesGlyphTextGlyph(Layout* layout, SpeciesGlyph* aliasSpeciesGlyph); - -std::vector getConnectedSpeciesGlyphReferences(Layout* layout, SpeciesGlyph* speciesGlyph); - -int getNumRequiredAliasSpeciesGlyphs(const int numConnectedEdges, const int maxNumConnectedEdges); - -int createAliasReactionGlyph(SBMLDocument* document, Layout* layout, ReactionGlyph* reactionGlyph); - -ReactionGlyph* createAliasReactionGlyph(Layout* layout, ReactionGlyph* reactionGlyph); - -void setAliasReactionGlyphTextGlyph(Layout* layout, ReactionGlyph* aliasReactionGlyph, ReactionGlyph* reactionGlyph); - -int createAliasSpeciesReferenceGlyphs(SBMLDocument* document, Layout* layout, ReactionGlyph* referenceReactionGlyph, ReactionGlyph* reactionGlyph); - -SpeciesReferenceGlyph* createAliasSpeciesReferenceGlyph(ReactionGlyph* reactionGlyph, SpeciesReferenceGlyph* referenceSpeciesReferenceGlyph, const std::string& speciesGlyphId, unsigned int stoichiometryIndex = 0); - -void setTextGlyphs(Layout* layout); - -void clearTextGlyphs(Layout* layout); - -void clearReactionTextGlyphs(Layout* layout); - -void setCompartmentTextGlyphs(Layout* layout); - -void setSpeciesTextGlyphs(Layout* layout); - -void setReactionTextGlyphs(Layout* layout); - -CompartmentGlyph* createCompartmentGlyph(Layout* layout, const std::string& compartmentId, const std::vector>& userData = {}); - -SpeciesGlyph* createSpeciesGlyph(Layout* layout, const std::string& speciesId, const std::vector>& userData = {}); - -SpeciesGlyph* createEmptySpeciesGlyph(Layout* layout, const std::string& reactionGlyphId); - -ReactionGlyph* createReactionGlyph(Layout* layout, const std::string& reactionId, const std::vector>& userData = {}); - -SpeciesReferenceGlyph* createSpeciesReferenceGlyph(Layout* layout, ReactionGlyph* reactionGlyph, const std::string& speciesId, unsigned int stoichiometryIndex, const int maxNumConnectedEdges, const std::vector>& userData = {}); - -SpeciesReferenceGlyph* createSpeciesReferenceGlyph(ReactionGlyph* reactionGlyph, const std::string& speciesId, unsigned int stoichiometryIndex); - CompartmentGlyph* getCompartmentGlyphOfReactionGlyph(Model* model, Layout* layout, ReactionGlyph* reactionGlyph); CompartmentGlyph* getDefaultCompartmentGlyph(Layout* layout); @@ -214,24 +46,14 @@ const int getIndexOfConnectedSpeciesGlyph(std::vector sp TextGlyph* createAssociatedTextGlyph(Layout* layout, GraphicalObject* graphicalObject); -void setGraphicalObjectUserData(GraphicalObject* graphicalObject, const std::vector>& userData); - void setGraphicalObjectBoundingBox(GraphicalObject* graphicalObject); void setReactionGlyphCurve(ReactionGlyph* reactionGlyph); -void setSpeciesReferenceGlyphCurve(SpeciesReferenceGlyph* speciesReferenceGlyph, SpeciesReferenceGlyph* referenceSpeciesReferenceGlyph); - -void setSpeciesReferenceGlyphCurve(SpeciesReferenceGlyph* speciesReferenceGlyph); - int removeReactionGlyphCurve(ReactionGlyph* reactionGlyph); void setTextGlyphBoundingBox(TextGlyph* textGlyph, GraphicalObject* graphicalObject, const double& padding = 0.0); -void addCurveSegment(Curve* curve, LineSegment* referenceLineSegment, const double& padding); - -void setCurveCubicBezier(Curve* curve, const double& x = 0.0, const double& y = 0.0); - Compartment* findCompartmentGlyphCompartment(Model* model, CompartmentGlyph* compartmentGlyph); Compartment* findSpeciesGlyphCompartment(Model* model, SpeciesGlyph* speciesGlyph); @@ -280,22 +102,12 @@ std::vector getSpeciesReferenceGlyphs(ReactionGlyph* rea const std::string getTextGlyphUniqueId(Layout* layout, GraphicalObject* graphicalObject); -const std::string getCompartmentGlyphId(Layout* layout, const std::string compartmentId); - -const std::string getSpeciesGlyphId(Layout* layout, const std::string speciesId); - -const std::string getReactionGlyphId(Layout* layout, const std::string reactionId); - -const std::string getSpeciesReferenceGlyphId(ReactionGlyph* reactionGlyph, const std::string speciesGlyphId, unsigned int stoichiometryIndex = 0); - const std::string getIdOfSpeciesReferenceGlyphConnectedToNewSpeciesGlyph(std::string speciesReferenceGlyphId, const std::string& originalSpeciesGlyphId, const std::string& aliasSpeciesGlyphId); const bool layoutContainsGlyphs(Layout* layout); const bool isGraphicalObject(SBase* sbase); -const int getStoichiometryAsInteger(SpeciesReferenceGlyph* speciesReferenceGlyph); - const int getStoichiometryAsInteger(SimpleSpeciesReference* speciesReference); void updateAssociatedTextGlyphsPositionX(Layout* layout, GraphicalObject* graphicalObject, const double& movedDistanceX); @@ -318,74 +130,6 @@ int setCurveMiddlePositionX(Curve* curve, const double& x); int setCurveMiddlePositionY(Curve* curve, const double& y); -void alignGraphicalObjects(Layout* layout, std::vector graphicalObjects, const std::string& alignment, const bool ignoreLockedNodes); - -void alignGraphicalObjectsToTop(Layout* layout, std::vector graphicalObjects, const bool ignoreLockedNodes); - -const double getTopAlignmentPosition(std::vector graphicalObjects, const bool ignoreLockedNodes); - -void alignGraphicalObjectsToVerticalCenter(Layout* layout, std::vector graphicalObjects, const bool ignoreLockedNodes); - -const double getVerticalCenterAlignmentPosition(std::vector graphicalObjects, const bool ignoreLockedNodes); - -void alignGraphicalObjectsToBottom(Layout* layout, std::vector graphicalObjects, const bool ignoreLockedNodes); - -const double getBottomAlignmentPosition(std::vector graphicalObjects, const bool ignoreLockedNodes); - -void alignGraphicalObjectsToLeft(Layout* layout, std::vector graphicalObjects, const bool ignoreLockedNodes); - -const double getLeftAlignmentPosition(std::vector graphicalObjects, const bool ignoreLockedNodes); - -void alignGraphicalObjectsToHorizontalCenter(Layout* layout, std::vector graphicalObjects, const bool ignoreLockedNodes); - -const double getHorizontalCenterAlignmentPosition(std::vector graphicalObjects, const bool ignoreLockedNodes); - -void alignGraphicalObjectsToRight(Layout* layout, std::vector graphicalObjects, const bool ignoreLockedNodes); - -const double getRightAlignmentPosition(std::vector graphicalObjects, const bool ignoreLockedNodes); - -void alignGraphicalObjectsCircularly(Layout* layout, std::vector graphicalObjects, const bool ignoreLockedNodes); - -void distributeGraphicalObjects(Layout* layout, std::vector graphicalObjects, const std::string& direction, const double& spacing); - -void distributeGraphicalObjectsHorizontally(Layout* layout, std::vector graphicalObjects, const double& spacing); - -void distributeEvenGraphicalObjectsHorizontally(Layout* layout, std::vector graphicalObjects, const double& minX, const double& maxX, const double& distance); - -void distributeOddGraphicalObjectsHorizontally(Layout* layout, std::vector graphicalObjects, const double& minX, const double& maxX, const double& distance); - -void distributeGraphicalObjectsVertically(Layout* layout, std::vector graphicalObjects, const double& spacing); - -void distributeEvenGraphicalObjectsVertically(Layout* layout, std::vector graphicalObjects, const double& minY, const double& maxY, const double& distance); - -void distributeOddGraphicalObjectsVertically(Layout* layout, std::vector graphicalObjects, const double& minY, const double& maxY, const double& distance); - -const double findDistributionDistance(const double& minPosition, const double& maxPosition, const unsigned int& numGraphicalObjects, const double& spacing); - -std::vector getSortedNodeIdsVector(std::set > nodeIds); - -const double getMinPositionX(std::vector graphicalObjects); - -const double getMinPositionY(std::vector graphicalObjects); - -const double getMaxPositionX(std::vector graphicalObjects); - -const double getMaxPositionY(std::vector graphicalObjects); - -const double getMinCenterX(std::vector graphicalObjects); - -const double getMinCenterY(std::vector graphicalObjects); - -const double getMaxCenterX(std::vector graphicalObjects); - -const double getMaxCenterY(std::vector graphicalObjects); - -const double getDefaultAutoLayoutPadding(); - -const double getAliasSpeciesGlyphPadding(); - -const double getAliasReactionGlyphPadding(); - const bool isValidLayoutDimensionWidthValue(const double& width, SBase* sBase = NULL); const bool isValidLayoutDimensionHeightValue(const double& height, SBase* sBase = NULL); @@ -420,16 +164,8 @@ const bool isValidDimensionValue(const double& dimension, SBase* sBase = NULL); const bool isValidDoubleValue(const double& value, SBase* sBase = NULL); -const bool isValidAlignment(const std::string& alignment, SBase* sBase = NULL); - -const bool isValidDistributionDirection(const std::string& direction, SBase* sBase = NULL); - std::vector getValidRoleValues(); -std::vector getValidAlignmentValues(); - -std::vector getValidDistributionDirectionValues(); - } #endif diff --git a/src/libsbmlnetwork_render.cpp b/src/libsbmlnetwork_render.cpp index 543180f..44fae05 100755 --- a/src/libsbmlnetwork_render.cpp +++ b/src/libsbmlnetwork_render.cpp @@ -1,9 +1,10 @@ #include "libsbmlnetwork_render.h" #include "libsbmlnetwork_layout.h" #include "libsbmlnetwork_render_helpers.h" -#include "libsbmlnetwork_sbmldocument_helpers.h" -#include "colors/libsbmlnetwork_colors.h" -#include "styles/libsbmlnetwork_styles.h" +#include "features/colors/libsbmlnetwork_colors.h" +#include "features/styles/libsbmlnetwork_styles.h" +#include "features/error_log/libsbmlnetwork_error_log.h" +#include "features/defaults/libsbmlnetwork_defaults_render.h" namespace LIBSBMLNETWORK_CPP_NAMESPACE { @@ -115,7 +116,7 @@ int setValue(ColorDefinition* colorDefinition, const std::string& value) { return 0; } else - addErrorToLog(colorDefinition, "The value " + value + " is not a valid color value."); + error_log_addErrorToLog(colorDefinition, "The value " + value + " is not a valid color value."); } return -1; @@ -3271,47 +3272,47 @@ int addGeometricShape(RenderGroup* renderGroup, const std::string& shape) { Transformation2D* shapeObject = NULL; if (stringCompare(shape, "square")) { shapeObject = renderGroup->createRectangle(); - setDefaultSquareShapeFeatures((Rectangle*)shapeObject); + defaults_setDefaultSquareShapeFeatures((Rectangle*)shapeObject); } else if (stringCompare(shape, "rectangle")) { shapeObject = renderGroup->createRectangle(); - setDefaultRectangleShapeFeatures((Rectangle*)shapeObject); + defaults_setDefaultRectangleShapeFeatures((Rectangle*)shapeObject); } else if (stringCompare(shape, "circle")) { shapeObject = renderGroup->createEllipse(); - setDefaultCircleShapeFeatures((Ellipse*)shapeObject); + defaults_setDefaultCircleShapeFeatures((Ellipse*)shapeObject); } else if (stringCompare(shape, "ellipse")) { shapeObject = renderGroup->createEllipse(); - setDefaultEllipseShapeFeatures((Ellipse*)shapeObject); + defaults_setDefaultEllipseShapeFeatures((Ellipse*)shapeObject); } else if (stringCompare(shape, "triangle")) { shapeObject = renderGroup->createPolygon(); - setDefaultTriangleShapeFeatures((Polygon*)shapeObject); + defaults_setDefaultTriangleShapeFeatures((Polygon*)shapeObject); } else if (stringCompare(shape, "diamond")) { shapeObject = renderGroup->createPolygon(); - setDefaultDiamondShapeFeatures((Polygon*)shapeObject); + defaults_setDefaultDiamondShapeFeatures((Polygon*)shapeObject); } else if (stringCompare(shape, "pentagon")) { shapeObject = renderGroup->createPolygon(); - setDefaultPentagonShapeFeatures((Polygon*)shapeObject); + defaults_setDefaultPentagonShapeFeatures((Polygon*)shapeObject); } else if (stringCompare(shape, "hexagon")) { shapeObject = renderGroup->createPolygon(); - setDefaultHexagonShapeFeatures((Polygon*)shapeObject); + defaults_setDefaultHexagonShapeFeatures((Polygon*)shapeObject); } else if (stringCompare(shape, "octagon")) { shapeObject = renderGroup->createPolygon(); - setDefaultOctagonShapeFeatures((Polygon*)shapeObject); + defaults_setDefaultOctagonShapeFeatures((Polygon*)shapeObject); } else if (stringCompare(shape, "rendercurve")) { shapeObject = renderGroup->createCurve(); - setDefaultRenderCurveShapeFeatures((RenderCurve*)shapeObject); + defaults_setDefaultRenderCurveShapeFeatures((RenderCurve*)shapeObject); } else if (stringCompare(shape, "image")) { shapeObject = renderGroup->createImage(); - setDefaultImageShapeFeatures((Image*)shapeObject); + defaults_setDefaultImageShapeFeatures((Image*)shapeObject); } if (shapeObject) { diff --git a/src/libsbmlnetwork_render_helpers.cpp b/src/libsbmlnetwork_render_helpers.cpp index 8b004ef..36a2916 100755 --- a/src/libsbmlnetwork_render_helpers.cpp +++ b/src/libsbmlnetwork_render_helpers.cpp @@ -2,10 +2,11 @@ #include "libsbmlnetwork_layout.h" #include "libsbmlnetwork_render.h" #include "libsbmlnetwork_sbmldocument_render.h" -#include "libsbmlnetwork_sbmldocument_helpers.h" #include "libsbmlnetwork_layout_helpers.h" -#include "colors/libsbmlnetwork_colors.h" -#include "styles/libsbmlnetwork_styles.h" +#include "features/colors/libsbmlnetwork_colors.h" +#include "features/styles/libsbmlnetwork_styles.h" +#include "features/error_log/libsbmlnetwork_error_log.h" +#include "features/defaults/libsbmlnetwork_defaults_render.h" #include @@ -223,26 +224,6 @@ std::vector> getStyleRoles() { return roles; } -void addDefaultColors(GlobalRenderInformation* globalRenderInformation) { - addColor(globalRenderInformation, "white"); - addColor(globalRenderInformation, "black"); - addColor(globalRenderInformation, "lightgray"); - addColor(globalRenderInformation, "darkslategray"); - addColor(globalRenderInformation, "darkcyan"); - addColor(globalRenderInformation, "teal"); - addColor(globalRenderInformation, "silver"); -} - -void addColorsOfDefaultGeometricShapes(SBMLDocument* document, Style* style) { - addColor(document, style, "white"); - addColor(document, style, "black"); -} - -void addColorsOfDefaultGeometricShapes(GlobalRenderInformation* globalRenderInformation) { - addColor(globalRenderInformation, "white"); - addColor(globalRenderInformation, "black"); -} - const std::string getColorValue(RenderInformationBase* renderInformationBase, const std::string &colorId) { ColorDefinition* colorDefinition = renderInformationBase->getColorDefinition(colorId); if (colorDefinition) @@ -510,13 +491,6 @@ const std::string getLocalLineEndingId(SBMLDocument* document, SpeciesReferenceG return ""; } -void addDefaultLineEndings(GlobalRenderInformation* globalRenderInformation) { - addProductHeadLineEnding(globalRenderInformation); - addModifierHeadLineEnding(globalRenderInformation); - addActivatorHeadLineEnding(globalRenderInformation); - addInhibitorHeadLineEnding(globalRenderInformation); -} - void addProductHeadLineEnding(GlobalRenderInformation* globalRenderInformation) { if (!globalRenderInformation->getLineEnding("productHead")) { RenderPkgNamespaces renderPkgNamespaces(globalRenderInformation->getLevel(), globalRenderInformation->getVersion()); @@ -536,7 +510,7 @@ LineEnding* createProductHeadLineEnding(RenderPkgNamespaces* renderPkgNamespaces void setProductHeadLineEndingExclusiveFeatures(LineEnding* lineEnding) { RenderGroup* renderGroup = lineEnding->getGroup(); Polygon* triangle = renderGroup->createPolygon(); - setDefaultTriangleShapeFeatures(triangle); + defaults_setDefaultTriangleShapeFeatures(triangle); triangle->getElement(1)->setY(RelAbsVector(0.0, 50.0)); triangle->getElement(2)->setX(RelAbsVector(0.0, 0.0)); triangle->setFill("black"); @@ -561,7 +535,7 @@ LineEnding* createModifierHeadLineEnding(RenderPkgNamespaces* renderPkgNamespace void setModifierHeadLineEndingExclusiveFeatures(LineEnding* lineEnding) { RenderGroup* renderGroup = lineEnding->getGroup(); Ellipse* ellipse = renderGroup->createEllipse(); - setDefaultEllipseShapeFeatures(ellipse); + defaults_setDefaultEllipseShapeFeatures(ellipse); } void addActivatorHeadLineEnding(GlobalRenderInformation* globalRenderInformation) { @@ -583,7 +557,7 @@ LineEnding* createActivatorHeadLineEnding(RenderPkgNamespaces* renderPkgNamespac void setActivatorHeadLineEndingExclusiveFeatures(LineEnding* lineEnding) { RenderGroup* renderGroup = lineEnding->getGroup(); Polygon* diamond = renderGroup->createPolygon(); - setDefaultDiamondShapeFeatures(diamond); + defaults_setDefaultDiamondShapeFeatures(diamond); } void addInhibitorHeadLineEnding(GlobalRenderInformation* globalRenderInformation) { @@ -606,7 +580,7 @@ LineEnding* createInhibitorHeadLineEnding(RenderPkgNamespaces* renderPkgNamespac void setInhibitorHeadLineEndingExclusiveFeatures(LineEnding* lineEnding) { RenderGroup* renderGroup = lineEnding->getGroup(); Rectangle* rectangle = renderGroup->createRectangle(); - setDefaultRectangleShapeFeatures(rectangle); + defaults_setDefaultRectangleShapeFeatures(rectangle); rectangle->setX(RelAbsVector(0.0, 80.0)); rectangle->setWidth(RelAbsVector(0.0, 20.0)); rectangle->setRX(RelAbsVector(0.0, 0.0)); @@ -828,7 +802,7 @@ void addSpeciesReferenceGlyphLocalStyle(SpeciesReferenceGlyph* speciesReferenceG void setCompartmentGlyphRenderGroupFeatures(RenderGroup* renderGroup) { Rectangle* rectangle = renderGroup->createRectangle(); - setDefaultRectangleShapeFeatures(rectangle); + defaults_setDefaultRectangleShapeFeatures(rectangle); rectangle->setStroke(getDefaultPredefinedStyleFeatures()["compartment-border-color"]); rectangle->setStrokeWidth(std::stod(getDefaultPredefinedStyleFeatures()["compartment-border-width"])); rectangle->setFill(getDefaultPredefinedStyleFeatures()["compartment-fill-color"]); @@ -846,18 +820,18 @@ void setCompartmentGlyphTextGlyphRenderGroupFeatures(RenderGroup* renderGroup) { void setSpeciesGlyphRenderGroupFeatures(RenderGroup* renderGroup) { Rectangle* rectangle = renderGroup->createRectangle(); - setDefaultRectangleShapeFeatures(rectangle); + defaults_setDefaultRectangleShapeFeatures(rectangle); rectangle->setRX(RelAbsVector(std::stod(getDefaultPredefinedStyleFeatures()["species-border-radius-x"]), 0.0)); rectangle->setRY(RelAbsVector(std::stod(getDefaultPredefinedStyleFeatures()["species-border-radius-y"]), 0.0)); } void setEmptySpeciesGlyphRenderGroupFeatures(RenderGroup* renderGroup) { Ellipse* ellipse = renderGroup->createEllipse(); - setDefaultEllipseShapeFeatures(ellipse); + defaults_setDefaultEllipseShapeFeatures(ellipse); ellipse->setFill(getDefaultPredefinedStyleFeatures()["species-fill-color"]); ellipse->setStroke(getDefaultPredefinedStyleFeatures()["species-border-color"]); RenderCurve* curve = renderGroup->createCurve(); - setDefaultDiagonalRenderCurveFeatures(curve); + defaults_setDefaultDiagonalRenderCurveFeatures(curve); curve->setStroke(getDefaultPredefinedStyleFeatures()["species-border-color"]); curve->setStrokeWidth(std::stod(getDefaultPredefinedStyleFeatures()["species-border-width"])); } @@ -869,7 +843,7 @@ void setSpeciesGlyphTextGlyphRenderGroupFeatures(RenderGroup* renderGroup) { void setReactionGlyphRenderGroupFeatures(RenderGroup* renderGroup) { Ellipse* ellipse = renderGroup->createEllipse(); - setDefaultEllipseShapeFeatures(ellipse); + defaults_setDefaultEllipseShapeFeatures(ellipse); } void setReactionGlyphTextGlyphRenderGroupFeatures(RenderGroup* renderGroup) { @@ -879,7 +853,7 @@ void setReactionGlyphTextGlyphRenderGroupFeatures(RenderGroup* renderGroup) { } void setSpeciesReferenceGlyphRenderGroupFeatures(RenderGroup* renderGroup, SpeciesReferenceRole_t role) { - setDefault1DShapeFeatures(renderGroup); + defaults_setDefault1DShapeFeatures(renderGroup); if (role == SPECIES_ROLE_PRODUCT || role == SPECIES_ROLE_SIDEPRODUCT) renderGroup->setEndHead("productHead"); else if (role == SPECIES_ROLE_MODIFIER) @@ -900,191 +874,6 @@ void setGeneralTextGlyphRenderGroupFeatures(RenderGroup* renderGroup) { renderGroup->setVTextAnchor(getDefaultPredefinedStyleFeatures()["species-text-vertical-alignment"]); } -void setDefault1DShapeFeatures(GraphicalPrimitive1D* graphicalPrimitive1D) { - graphicalPrimitive1D->setStroke("black"); - graphicalPrimitive1D->setStrokeWidth(2.0); -} - -void setDefault2DShapeFeatures(GraphicalPrimitive2D* graphicalPrimitive2D) { - setDefault1DShapeFeatures(graphicalPrimitive2D); - graphicalPrimitive2D->setFill("white"); -} - -void setDefaultRectangleShapeFeatures(Rectangle* rectangle) { - setDefault2DShapeFeatures(rectangle); - rectangle->setX(RelAbsVector(0.0, 0.0)); - rectangle->setY(RelAbsVector(0.0, 0.0)); - rectangle->setWidth(RelAbsVector(0.0, 100.0)); - rectangle->setHeight(RelAbsVector(0.0, 100.0)); - rectangle->setRX(RelAbsVector(0.0, 10.0)); - rectangle->setRY(RelAbsVector(0.0, 10.0)); -} - -void setDefaultSquareShapeFeatures(Rectangle* square) { - setDefault2DShapeFeatures(square); - square->setX(RelAbsVector(0.0, 0.0)); - square->setY(RelAbsVector(0.0, 0.0)); - square->setWidth(RelAbsVector(0.0, 100.0)); - square->setRatio(1.0); - square->setRX(RelAbsVector(0.0, 0.0)); - square->setRY(RelAbsVector(0.0, 0.0)); -} - -void setDefaultEllipseShapeFeatures(Ellipse* ellipse) { - setDefault2DShapeFeatures(ellipse); - ellipse->setCX(RelAbsVector(0.0, 50.0)); - ellipse->setCY(RelAbsVector(0.0, 50.0)); - ellipse->setRX(RelAbsVector(0.0, 50.0)); - ellipse->setRY(RelAbsVector(0.0, 50.0)); - ellipse->setStroke("black"); - ellipse->setStrokeWidth(2.0); -} - -void setDefaultCircleShapeFeatures(Ellipse* circle) { - setDefault2DShapeFeatures(circle); - circle->setCX(RelAbsVector(0.0, 50.0)); - circle->setCY(RelAbsVector(0.0, 50.0)); - circle->setRX(RelAbsVector(0.0, 50.0)); - circle->setRatio(1.0); - circle->setStroke("black"); - circle->setStrokeWidth(2.0); -} - -void setDefaultTriangleShapeFeatures(Polygon* triangle) { - setDefault2DShapeFeatures(triangle); - RenderPoint* point = NULL; - point = triangle->createPoint(); - point->setX(RelAbsVector(0.0, 0.0)); - point->setY(RelAbsVector(0.0, 0.0)); - point = triangle->createPoint(); - point->setX(RelAbsVector(0.0, 100.0)); - point->setY(RelAbsVector(0.0, 0.0)); - point = triangle->createPoint(); - point->setX(RelAbsVector(0.0, 50.0)); - point->setY(RelAbsVector(0.0, 100.0)); -} - -void setDefaultDiamondShapeFeatures(Polygon* diamond) { - setDefault2DShapeFeatures(diamond); - RenderPoint* point = NULL; - point = diamond->createPoint(); - point->setX(RelAbsVector(0.0, 0.0)); - point->setY(RelAbsVector(0.0, 50.0)); - point = diamond->createPoint(); - point->setX(RelAbsVector(0.0, 50.0)); - point->setY(RelAbsVector(0.0, 0.0)); - point = diamond->createPoint(); - point->setX(RelAbsVector(0.0, 100.0)); - point->setY(RelAbsVector(0.0, 50.0)); - point = diamond->createPoint(); - point->setX(RelAbsVector(0.0, 50.0)); - point->setY(RelAbsVector(0.0, 100.0)); - -} - -void setDefaultPentagonShapeFeatures(Polygon* pentagon) { - setDefault2DShapeFeatures(pentagon); - const double pi = 3.14159265; - RenderPoint* point = NULL; - point = pentagon->createPoint(); - point->setX(RelAbsVector(0.0, 50. * (1 - std::sin(0.4 * pi)))); - point->setY(RelAbsVector(0.0, 50. * (1 - std::cos(0.4 * pi)))); - point = pentagon->createPoint(); - point->setX(RelAbsVector(0.0, 50.)); - point->setY(RelAbsVector(0.0, 0.)); - point = pentagon->createPoint(); - point->setX(RelAbsVector(0.0, 50. * (1 + std::sin(0.4 * pi)))); - point->setY(RelAbsVector(0.0, 50. * (1 - std::cos(0.4 * pi)))); - point = pentagon->createPoint(); - point->setX(RelAbsVector(0.0, 50. * (1 + std::sin(0.2 * pi)))); - point->setY(RelAbsVector(0.0, 50. * (1 + std::cos(0.2 * pi)))); - point = pentagon->createPoint(); - point->setX(RelAbsVector(0.0, 50. * (1 - std::sin(0.2 * pi)))); - point->setY(RelAbsVector(0.0, 50. * (1 + std::cos(0.2 * pi)))); -} - -void setDefaultHexagonShapeFeatures(Polygon* hexagon) { - setDefault2DShapeFeatures(hexagon); - RenderPoint* point = NULL; - point = hexagon->createPoint(); - point->setX(RelAbsVector(0.0, 0.0)); - point->setY(RelAbsVector(0.0, 25.0)); - point = hexagon->createPoint(); - point->setX(RelAbsVector(0.0, 50.0)); - point->setY(RelAbsVector(0.0, 0.0)); - point = hexagon->createPoint(); - point->setX(RelAbsVector(0.0, 100.0)); - point->setY(RelAbsVector(0.0, 25.0)); - point = hexagon->createPoint(); - point->setX(RelAbsVector(0.0, 100.0)); - point->setY(RelAbsVector(0.0, 75.0)); - point = hexagon->createPoint(); - point->setX(RelAbsVector(0.0, 50.0)); - point->setY(RelAbsVector(0.0, 100.0)); - point = hexagon->createPoint(); - point->setX(RelAbsVector(0.0, 0.0)); - point->setY(RelAbsVector(0.0, 75.0)); -} - -void setDefaultOctagonShapeFeatures(Polygon* octagon) { - setDefault2DShapeFeatures(octagon); - const double pi = 3.14159265; - RenderPoint* point = NULL; - point = octagon->createPoint(); - point->setX(RelAbsVector(0.0, 0.0)); - point->setY(RelAbsVector(0.0, 50.0)); - point = octagon->createPoint(); - point->setX(RelAbsVector(0.0, 50. * (1 - std::cos(pi / 4.0)))); - point->setY(RelAbsVector(0.0, 50. * (1 - std::sin(pi / 4.0)))); - point = octagon->createPoint(); - point->setX(RelAbsVector(0.0, 50.0)); - point->setY(RelAbsVector(0.0, 0.0)); - point = octagon->createPoint(); - point->setX(RelAbsVector(0.0, 50. * (1 + std::cos(pi / 4.0)))); - point->setY(RelAbsVector(0.0, 50. * (1 - std::sin(pi / 4.0)))); - point = octagon->createPoint(); - point->setX(RelAbsVector(0.0, 100.0)); - point->setY(RelAbsVector(0.0, 50.0)); - point = octagon->createPoint(); - point->setX(RelAbsVector(0.0, 50. * (1 + std::cos(pi / 4.0)))); - point->setY(RelAbsVector(0.0, 50. * (1 + std::sin(pi / 4.0)))); - point = octagon->createPoint(); - point->setX(RelAbsVector(0.0, 50.0)); - point->setY(RelAbsVector(0.0, 100.0)); - point = octagon->createPoint(); - point->setX(RelAbsVector(0.0, 50. * (1 - std::cos(pi / 4.0)))); - point->setY(RelAbsVector(0.0, 50. * (1 + std::sin(pi / 4.0)))); -} - -void setDefaultRenderCurveShapeFeatures(RenderCurve* renderCurve) { - setDefault1DShapeFeatures(renderCurve); - RenderPoint* point = NULL; - point = renderCurve->createPoint(); - point->setX(RelAbsVector(0.0, 0.0)); - point->setY(RelAbsVector(0.0, 50.0)); - point = renderCurve->createPoint(); - point->setX(RelAbsVector(0.0, 100.0)); - point->setY(RelAbsVector(0.0, 50.0)); -} - -void setDefaultImageShapeFeatures(Image* image) { - image->setX(RelAbsVector(0.0, 0.0)); - image->setY(RelAbsVector(0.0, 0.0)); - image->setWidth(RelAbsVector(0.0, 100.0)); - image->setHeight(RelAbsVector(0.0, 100.0)); -} - -void setDefaultDiagonalRenderCurveFeatures(RenderCurve* renderCurve) { - setDefault1DShapeFeatures(renderCurve); - RenderPoint* point = NULL; - point = renderCurve->createPoint(); - point->setX(RelAbsVector(0.0, 100.0)); - point->setY(RelAbsVector(0.0, 0.0)); - point = renderCurve->createPoint(); - point->setX(RelAbsVector(0.0, 0.0)); - point->setY(RelAbsVector(0.0, 100.0)); -} - void unifyGeometricShapeMutualFeatures(RenderGroup* renderGroup) { if (renderGroup && getNumGeometricShapes(renderGroup) > 1) { std::string strokeColor = "black"; @@ -1230,218 +1019,11 @@ const bool canPotentiallyHaveGeometricShape(GraphicalObject* graphicalObject) { return false; } -std::string getErrorLog(RenderInformationBase* renderInformation) { - std::string errorLog = ""; - if (renderInformation) - errorLog += prepareErrorMessage(getUserData(renderInformation, "error_log"), errorLog); - for (unsigned int i = 0; i < renderInformation->getNumColorDefinitions(); i++) - errorLog += prepareErrorMessage(getErrorLog(renderInformation->getColorDefinition(i)), errorLog); - for (unsigned int i = 0; i < renderInformation->getNumGradientDefinitions(); i++) { - GradientBase* gradientBase = renderInformation->getGradientDefinition(i); - errorLog += prepareErrorMessage(getErrorLog(gradientBase), errorLog); - for (unsigned int j = 0; j < gradientBase->getNumGradientStops(); j++) - errorLog += prepareErrorMessage(getErrorLog(gradientBase->getGradientStop(j)), errorLog); - } - for (unsigned int i = 0; i < renderInformation->getNumLineEndings(); i++) - errorLog += prepareErrorMessage(getErrorLog(renderInformation->getLineEnding(i)), errorLog); - if (renderInformation->isGlobalRenderInformation()) { - for (unsigned int i = 0; i < ((GlobalRenderInformation*)renderInformation)->getNumGlobalStyles(); i++) - errorLog += prepareErrorMessage(getErrorLog(((GlobalRenderInformation *) renderInformation)->getGlobalStyle(i)), errorLog); - } - else if (renderInformation->isLocalRenderInformation()) { - for (unsigned int i = 0; i < ((LocalRenderInformation*)renderInformation)->getNumLocalStyles(); i++) - errorLog += prepareErrorMessage(getErrorLog(((LocalRenderInformation *) renderInformation)->getLocalStyle(i)), errorLog); - } - - return errorLog; -} - -std::string getErrorLog(ColorDefinition* colorDefinition) { - std::string errorLog = ""; - if (colorDefinition) - errorLog += prepareErrorMessage(getUserData(colorDefinition, "error_log"), errorLog); - - return errorLog; -} - -std::string getErrorLog(GradientBase* gradientBase) { - std::string errorLog = ""; - if (gradientBase) - errorLog += prepareErrorMessage(getUserData(gradientBase, "error_log"), errorLog); - - return errorLog; -} - -std::string getErrorLog(GradientStop* gradientStop) { - std::string errorLog = ""; - if (gradientStop) - errorLog += prepareErrorMessage(getUserData(gradientStop, "error_log"), errorLog); - - return errorLog; -} - -std::string getErrorLog(LineEnding* lineEnding) { - std::string errorLog = ""; - if (lineEnding) - errorLog += prepareErrorMessage(getUserData(lineEnding, "error_log"), errorLog); - - return errorLog; -} - -std::string getErrorLog(Style* style) { - std::string errorLog = ""; - if (style) { - errorLog += prepareErrorMessage(getUserData(style, "error_log"), errorLog); - errorLog += prepareErrorMessage(getErrorLog(style->getGroup()), errorLog); - } - - return errorLog; -} - -std::string getErrorLog(RenderGroup* renderGroup) { - std::string errorLog = ""; - if (renderGroup) { - errorLog += prepareErrorMessage(getUserData(renderGroup, "error_log"), errorLog); - for (unsigned int i = 0; i < renderGroup->getNumElements(); i++) - errorLog += prepareErrorMessage(getErrorLog(renderGroup->getElement(i)), errorLog); - } - - return errorLog; -} - -std::string getErrorLog(Transformation2D* transformation2D) { - std::string errorLog = ""; - if (transformation2D) - errorLog += prepareErrorMessage(getUserData(transformation2D, "error_log"), errorLog); - - return errorLog; -} - -void clearErrorLog(RenderInformationBase* renderInformation) { - if (renderInformation) { - setUserData(renderInformation, "error_log", ""); - for (unsigned int i = 0; i < renderInformation->getNumColorDefinitions(); i++) - clearErrorLog(renderInformation->getColorDefinition(i)); - for (unsigned int i = 0; i < renderInformation->getNumGradientDefinitions(); i++) { - GradientBase* gradientBase = renderInformation->getGradientDefinition(i); - clearErrorLog(gradientBase); - for (unsigned int j = 0; j < gradientBase->getNumGradientStops(); j++) - clearErrorLog(gradientBase->getGradientStop(j)); - } - for (unsigned int i = 0; i < renderInformation->getNumLineEndings(); i++) - clearErrorLog(renderInformation->getLineEnding(i)); - if (renderInformation->isGlobalRenderInformation()) { - for (unsigned int i = 0; i < ((GlobalRenderInformation*)renderInformation)->getNumGlobalStyles(); i++) - clearErrorLog(((GlobalRenderInformation*)renderInformation)->getGlobalStyle(i)); - } - else if (renderInformation->isLocalRenderInformation()) { - for (unsigned int i = 0; i < ((LocalRenderInformation*)renderInformation)->getNumLocalStyles(); i++) - clearErrorLog(((LocalRenderInformation*)renderInformation)->getLocalStyle(i)); - } - } -} - -void clearErrorLog(ColorDefinition* colorDefinition) { - if (colorDefinition) - setUserData(colorDefinition, "error_log", ""); -} - -void clearErrorLog(GradientBase* gradientBase) { - if (gradientBase) - setUserData(gradientBase, "error_log", ""); -} - -void clearErrorLog(GradientStop* gradientStop) { - if (gradientStop) - setUserData(gradientStop, "error_log", ""); -} - -void clearErrorLog(LineEnding* lineEnding) { - if (lineEnding) - setUserData(lineEnding, "error_log", ""); -} - -void clearErrorLog(Style* style) { - if (style) { - setUserData(style, "error_log", ""); - clearErrorLog( style->getGroup()); - } -} - -void clearErrorLog(RenderGroup* renderGroup) { - if (renderGroup) { - setUserData(renderGroup, "error_log", ""); - for (unsigned int j = 0; j < renderGroup->getNumElements(); j++) - clearErrorLog(renderGroup->getElement(j)); - } -} - -void clearErrorLog(Transformation2D* transformation2D) { - if (transformation2D) - setUserData(transformation2D, "error_log", ""); -} - -void freeUserData(RenderInformationBase* renderInformation) { - for (unsigned int i = 0; i < renderInformation->getNumColorDefinitions(); i++) - freeUserData(renderInformation->getColorDefinition(i)); - for (unsigned int i = 0; i < renderInformation->getNumGradientDefinitions(); i++) { - GradientBase* gradientBase = renderInformation->getGradientDefinition(i); - freeUserData(gradientBase); - for (unsigned int j = 0; j < gradientBase->getNumGradientStops(); j++) - freeUserData(gradientBase->getGradientStop(j)); - } - for (unsigned int i = 0; i < renderInformation->getNumLineEndings(); i++) - freeUserData(renderInformation->getLineEnding(i)); - if (renderInformation->isGlobalRenderInformation()) { - for (unsigned int i = 0; i < ((GlobalRenderInformation*)renderInformation)->getNumGlobalStyles(); i++) - freeUserData(((GlobalRenderInformation*)renderInformation)->getGlobalStyle(i)); - } - else if (renderInformation->isLocalRenderInformation()) { - for (unsigned int i = 0; i < ((LocalRenderInformation*)renderInformation)->getNumLocalStyles(); i++) - freeUserData(((LocalRenderInformation*)renderInformation)->getLocalStyle(i)); - } -} - -std::vector> getUserData(RenderInformationBase* renderInformation) { - std::vector> userData; - for (unsigned int i = 0; i < renderInformation->getNumColorDefinitions(); i++) { - auto colorDefinitionUserData = renderInformation->getColorDefinition(i)->getUserData(); - if (colorDefinitionUserData) - userData.push_back(*(std::map*)colorDefinitionUserData); - } - for (unsigned int i = 0; i < renderInformation->getNumGradientDefinitions(); i++) { - auto gradientDefinitionUserData = renderInformation->getGradientDefinition(i)->getUserData(); - if (gradientDefinitionUserData) - userData.push_back(*(std::map*)gradientDefinitionUserData); - } - for (unsigned int i = 0; i < renderInformation->getNumLineEndings(); i++) { - auto lineEndingUserData = renderInformation->getLineEnding(i)->getUserData(); - if (lineEndingUserData) - userData.push_back(*(std::map*)lineEndingUserData); - } - if (renderInformation->isGlobalRenderInformation()) { - for (unsigned int i = 0; i < ((GlobalRenderInformation*)renderInformation)->getNumGlobalStyles(); i++) { - auto globalStyleUserData = ((GlobalRenderInformation*)renderInformation)->getGlobalStyle(i)->getUserData(); - if (globalStyleUserData) - userData.push_back(*(std::map*)globalStyleUserData); - } - } - else if (renderInformation->isLocalRenderInformation()) { - for (unsigned int i = 0; i < ((LocalRenderInformation*)renderInformation)->getNumLocalStyles(); i++) { - auto localStyleUserData = ((LocalRenderInformation*)renderInformation)->getLocalStyle(i)->getUserData(); - if (localStyleUserData) - userData.push_back(*(std::map*)localStyleUserData); - } - } - - return userData; -} - const bool isValidBackgroundColorValue(const std::string& backgroundColor, SBase* sBase) { if (isValidColorValue(backgroundColor)) return true; - addErrorToLog(sBase, "The entered value is not a valid background color value"); + error_log_addErrorToLog(sBase, "The entered value is not a valid background color value"); return false; } @@ -1449,7 +1031,7 @@ const bool isValidSpreadMethodValue(const std::string& spreadMethod, SBase* sBas if (isValueValid(spreadMethod, getValidSpreadMethodValues())) return true; - addErrorToLog(sBase, createErrorMessage(spreadMethod, getValidSpreadMethodValues())); + error_log_addErrorToLog(sBase, error_log_createErrorMessage(spreadMethod, getValidSpreadMethodValues())); return false; } @@ -1477,7 +1059,7 @@ const bool isValidStopColorValue(const std::string& stopColor, SBase* sBase) { if (isValidColorValue(stopColor)) return true; - addErrorToLog(sBase, "The entered value is not a valid stop color value"); + error_log_addErrorToLog(sBase, "The entered value is not a valid stop color value"); return false; } @@ -1525,7 +1107,7 @@ const bool isValidStrokeColorValue(const std::string& stroke, SBase* sBase) { if (isValidColorValue(stroke)) return true; - addErrorToLog(sBase, "The value entered is not a valid stroke color value"); + error_log_addErrorToLog(sBase, "The value entered is not a valid stroke color value"); return false; } @@ -1533,7 +1115,7 @@ const bool isValidStrokeWidthValue(const double& strokeWidth, SBase* sBase) { if (isValidDoubleValue(strokeWidth, sBase) && strokeWidth > 0.0001) return true; - addErrorToLog(sBase, "The value " + std::to_string(strokeWidth) + " is not a valid stroke width value"); + error_log_addErrorToLog(sBase, "The value " + std::to_string(strokeWidth) + " is not a valid stroke width value"); return false; } @@ -1550,7 +1132,7 @@ const bool isValidStrokeDashValue(const unsigned int& dash, SBase* sBase) { if (isValidDoubleValue(dash, sBase) && dash > 0.000) return true; - addErrorToLog(sBase, "The value " + std::to_string(dash) + " is not a valid stroke dash value"); + error_log_addErrorToLog(sBase, "The value " + std::to_string(dash) + " is not a valid stroke dash value"); return false; } @@ -1558,7 +1140,7 @@ const bool isValidFontColorValue(const std::string& fontColor, SBase* sBase) { if (isValidColorValue(fontColor)) return true; - addErrorToLog(sBase, "The value entered value is not a valid font color value"); + error_log_addErrorToLog(sBase, "The value entered value is not a valid font color value"); return false; } @@ -1574,7 +1156,7 @@ const bool isValidFontWeightValue(const std::string& fontWeight, SBase* sBase) { if (isValueValid(fontWeight, getValidFontWeightValues())) return true; - addErrorToLog(sBase, createErrorMessage(fontWeight, getValidFontWeightValues())); + error_log_addErrorToLog(sBase, error_log_createErrorMessage(fontWeight, getValidFontWeightValues())); return false; } @@ -1582,7 +1164,7 @@ const bool isValidFontStyleValue(const std::string& fontStyle, SBase* sBase) { if (isValueValid(fontStyle, getValidFontStyleValues())) return true; - addErrorToLog(sBase, createErrorMessage(fontStyle, getValidFontStyleValues())); + error_log_addErrorToLog(sBase, error_log_createErrorMessage(fontStyle, getValidFontStyleValues())); return false; } @@ -1590,7 +1172,7 @@ const bool isValidTextAnchorValue(const std::string& textAnchor, SBase* sBase) { if (isValueValid(textAnchor, getValidTextAnchorValues())) return true; - addErrorToLog(sBase, createErrorMessage(textAnchor, getValidTextAnchorValues())); + error_log_addErrorToLog(sBase, error_log_createErrorMessage(textAnchor, getValidTextAnchorValues())); return false; } @@ -1598,7 +1180,7 @@ const bool isValidVTextAnchorValue(const std::string& vtextAnchor, SBase* sBase) if (isValueValid(vtextAnchor, getValidVTextAnchorValues())) return true; - addErrorToLog(sBase, createErrorMessage(vtextAnchor, getValidVTextAnchorValues())); + error_log_addErrorToLog(sBase, error_log_createErrorMessage(vtextAnchor, getValidVTextAnchorValues())); return false; } @@ -1606,7 +1188,7 @@ const bool isValidFillColorValue(const std::string& fillColor, SBase* sBase) { if (isValidColorValue(fillColor)) return true; - addErrorToLog(sBase, "The entered value is not a valid fill color value"); + error_log_addErrorToLog(sBase, "The entered value is not a valid fill color value"); return false; } @@ -1614,7 +1196,7 @@ const bool isValidFillRuleValue(const std::string& fillRule, SBase* sBase) { if (isValueValid(fillRule, getValidFillRuleValues())) return true; - addErrorToLog(sBase, createErrorMessage(fillRule, getValidFillRuleValues())); + error_log_addErrorToLog(sBase, error_log_createErrorMessage(fillRule, getValidFillRuleValues())); return false; } @@ -1630,7 +1212,7 @@ const bool isValidGeometricShapeName(const std::string& geometricShapeName, SBas if (isValueValid(geometricShapeName, getValidGeometricShapeNameValues())) return true; - addErrorToLog(sBase, createErrorMessage(geometricShapeName, getValidGeometricShapeNameValues())); + error_log_addErrorToLog(sBase, error_log_createErrorMessage(geometricShapeName, getValidGeometricShapeNameValues())); return false; } @@ -1654,7 +1236,7 @@ const bool isValidGeometricShapeRatioValue(const double& ratio, SBase* sBase) { if (isValidDoubleValue(ratio, sBase) && ratio > 0.0001) return true; - addErrorToLog(sBase, "The value " + std::to_string(ratio) + " is not a valid geometric shape ratio value"); + error_log_addErrorToLog(sBase, "The value " + std::to_string(ratio) + " is not a valid geometric shape ratio value"); return false; } @@ -1714,7 +1296,7 @@ const bool isValidRelAbsVectorPositiveValue(const RelAbsVector& relAbsVectorValu if (isValidRelAbsVectorValue(relAbsVectorValue, sBase) && relAbsVectorValue.getAbsoluteValue() >= 0.000) return true; - addErrorToLog(sBase, "The value " + std::to_string(relAbsVectorValue.getAbsoluteValue()) + " is not a valid positive value"); + error_log_addErrorToLog(sBase, "The value " + std::to_string(relAbsVectorValue.getAbsoluteValue()) + " is not a valid positive value"); return false; } @@ -1722,14 +1304,14 @@ const bool isValidRelAbsVectorValue(const RelAbsVector& relAbsVectorValue, SBase if (isValidDoubleValue(relAbsVectorValue.getAbsoluteValue(), sBase) && isValidDoubleValue(relAbsVectorValue.getRelativeValue(), sBase)) return true; - addErrorToLog(sBase, "The value " + std::to_string(relAbsVectorValue.getAbsoluteValue()) + " is not a valid double value"); + error_log_addErrorToLog(sBase, "The value " + std::to_string(relAbsVectorValue.getAbsoluteValue()) + " is not a valid double value"); return false; } const bool isValidRelAbsVectorRelativeValue(const double& relativeValue, SBase* sBase) { if (isValidDoubleValue(relativeValue, sBase) && relativeValue >= 0.0 && relativeValue <= 100.0) return true; - addErrorToLog(sBase, "The value " + std::to_string(relativeValue) + " is not a valid relative value"); + error_log_addErrorToLog(sBase, "The value " + std::to_string(relativeValue) + " is not a valid relative value"); return false; } diff --git a/src/libsbmlnetwork_render_helpers.h b/src/libsbmlnetwork_render_helpers.h index 6256962..a060838 100755 --- a/src/libsbmlnetwork_render_helpers.h +++ b/src/libsbmlnetwork_render_helpers.h @@ -71,12 +71,6 @@ std::vector> getStyleRoles(); void setGeneralTextGlyphRenderGroupFeatures(RenderGroup* renderGroup); -void addDefaultColors(GlobalRenderInformation* globalRenderInformation); - -void addColorsOfDefaultGeometricShapes(SBMLDocument* document, Style* style); - -void addColorsOfDefaultGeometricShapes(GlobalRenderInformation* globalRenderInformation); - const std::string getColorValue(RenderInformationBase* renderInformationBase, const std::string &colorId); const std::string getColorId(RenderInformationBase* renderInformationBase, const std::string &colorValue); @@ -121,8 +115,6 @@ const bool isLocal(SBMLDocument* document, LineEnding* lineEnding, SpeciesRefere const std::string getLocalLineEndingId(SBMLDocument* document, SpeciesReferenceGlyph* speciesReferenceGlyph); -void addDefaultLineEndings(GlobalRenderInformation* globalRenderInformation); - void addProductHeadLineEnding(GlobalRenderInformation* globalRenderInformation); LineEnding* createProductHeadLineEnding(RenderPkgNamespaces* renderPkgNamespaces); @@ -227,34 +219,6 @@ void setReactionGlyphTextGlyphRenderGroupFeatures(RenderGroup* renderGroup); void setSpeciesReferenceGlyphRenderGroupFeatures(RenderGroup* renderGroup, SpeciesReferenceRole_t role); -void setDefault1DShapeFeatures(GraphicalPrimitive1D* graphicalPrimitive1D); - -void setDefault2DShapeFeatures(GraphicalPrimitive2D* graphicalPrimitive2D); - -void setDefaultRectangleShapeFeatures(Rectangle* rectangle); - -void setDefaultSquareShapeFeatures(Rectangle* square); - -void setDefaultEllipseShapeFeatures(Ellipse* ellipse); - -void setDefaultCircleShapeFeatures(Ellipse* circle); - -void setDefaultTriangleShapeFeatures(Polygon* triangle); - -void setDefaultDiamondShapeFeatures(Polygon* diamond); - -void setDefaultPentagonShapeFeatures(Polygon* pentagon); - -void setDefaultHexagonShapeFeatures(Polygon* pentagon); - -void setDefaultOctagonShapeFeatures(Polygon* pentagon); - -void setDefaultRenderCurveShapeFeatures(RenderCurve* renderCurve); - -void setDefaultImageShapeFeatures(Image* image); - -void setDefaultDiagonalRenderCurveFeatures(RenderCurve* renderCurve); - void unifyGeometricShapeMutualFeatures(RenderGroup* renderGroup); const std::string getGlobalStyleUniqueId(GlobalRenderInformation* globalRenderInformation, const std::string& type); @@ -291,42 +255,6 @@ const bool canHaveGeometricShape(GraphicalObject* graphicalObject); const bool canPotentiallyHaveGeometricShape(GraphicalObject* graphicalObject); -std::string getErrorLog(RenderInformationBase* renderInformation); - -std::string getErrorLog(ColorDefinition* colorDefinition); - -std::string getErrorLog(GradientBase* gradientBase); - -std::string getErrorLog(GradientStop* gradientStop); - -std::string getErrorLog(LineEnding* lineEnding); - -std::string getErrorLog(Style* style); - -std::string getErrorLog(RenderGroup* renderGroup); - -std::string getErrorLog(Transformation2D* transformation2D); - -void clearErrorLog(RenderInformationBase* renderInformation); - -void clearErrorLog(ColorDefinition* colorDefinition); - -void clearErrorLog(GradientBase* gradientBase); - -void clearErrorLog(GradientStop* gradientStop); - -void clearErrorLog(LineEnding* lineEnding); - -void clearErrorLog(Style* style); - -void clearErrorLog(RenderGroup* renderGroup); - -void clearErrorLog(Transformation2D* transformation2D); - -void freeUserData(RenderInformationBase* renderInformation); - -std::vector> getUserData(RenderInformationBase* renderInformationBase); - const bool isValidBackgroundColorValue(const std::string& backgroundColor, SBase* sBase = NULL); const bool isValidSpreadMethodValue(const std::string& spreadMethod, SBase* sBase = NULL); diff --git a/src/libsbmlnetwork_sbmldocument.cpp b/src/libsbmlnetwork_sbmldocument.cpp index cbdc0c8..72b5d34 100644 --- a/src/libsbmlnetwork_sbmldocument.cpp +++ b/src/libsbmlnetwork_sbmldocument.cpp @@ -1,10 +1,12 @@ #include "libsbmlnetwork_sbmldocument.h" -#include "libsbmlnetwork_sbmldocument_helpers.h" #include "libsbmlnetwork_layout_render.h" #include "libsbmlnetwork_sbmldocument_layout.h" #include "libsbmlnetwork_sbmldocument_render.h" #include "libsbmlnetwork_layout_helpers.h" #include "libsbmlnetwork_render_helpers.h" +#include "features/error_log/libsbmlnetwork_error_log.h" +#include "features/user_data/libsbmlnetwork_user_data.h" +#include "features/align_elements/libsbmlnetwork_align_species.h" namespace LIBSBMLNETWORK_CPP_NAMESPACE { @@ -50,50 +52,16 @@ namespace LIBSBMLNETWORK_CPP_NAMESPACE { } const std::string getErrorLog(SBMLDocument* document) { - std::string errorLog = ""; - if (document) { - errorLog = prepareErrorMessage(getUserData(document, "error_log"), errorLog); - ListOfLayouts* listOfLayouts = getListOfLayouts(document); - errorLog += prepareErrorMessage(getErrorLog(listOfLayouts), errorLog); - const int numLayouts = getNumLayouts(document); - for (int i = 0; i < numLayouts; i++) { - Layout* layout = getLayout(document, i); - errorLog += prepareErrorMessage(getErrorLog(layout), errorLog); - const int numLocalRenderInformation = getNumLocalRenderInformation(layout); - for (int j = 0; j < numLocalRenderInformation; j++) - errorLog += prepareErrorMessage(getErrorLog(getLocalRenderInformation(layout, j)), errorLog); - - } - const int numGlobalRenderInformation = getNumGlobalRenderInformation(document); - for (int i = 0; i < numGlobalRenderInformation; i++) - errorLog += prepareErrorMessage(getErrorLog(getGlobalRenderInformation(document, i)), errorLog); - } - - return errorLog; + return error_log_getErrorLog(document); } void clearErrorLog(SBMLDocument* document) { - if (document) { - setUserData(document, "error_log", ""); - ListOfLayouts* listOfLayouts = getListOfLayouts(document); - clearErrorLog(listOfLayouts); - const int numLayouts = getNumLayouts(document); - for (int i = 0; i < numLayouts; i++) { - Layout* layout = getLayout(document, i); - clearErrorLog(layout); - const int numLocalRenderInformation = getNumLocalRenderInformation(layout); - for (int j = 0; j < numLocalRenderInformation; j++) - clearErrorLog(getLocalRenderInformation(layout, j)); - } - const int numGlobalRenderInformation = getNumGlobalRenderInformation(document); - for (int i = 0; i < numGlobalRenderInformation; i++) - clearErrorLog(getGlobalRenderInformation(document, i)); - } + return error_log_clearErrorLog(document); } bool freeSBMLDocument(SBMLDocument* document) { if (document) { - freeUserData(document); + user_data_freeUserData(document); delete document; return true; } @@ -108,8 +76,8 @@ namespace LIBSBMLNETWORK_CPP_NAMESPACE { return false; } - int autolayout(SBMLDocument* document, const int maxNumConnectedEdges, bool useNameAsTextLabel, bool resetLockedElements, std::set > lockedNodesSet) { - const bool layoutIsAdded = !createDefaultLayoutLocations(document, maxNumConnectedEdges, useNameAsTextLabel, resetLockedElements, lockedNodesSet); + int autolayout(SBMLDocument* document, const int maxNumConnectedEdges, bool useNameAsTextLabel, bool resetFixedPositionElements, std::set > fixedPositionNodesSet) { + const bool layoutIsAdded = !createDefaultLayoutLocations(document, maxNumConnectedEdges, useNameAsTextLabel, resetFixedPositionElements, fixedPositionNodesSet); const bool renderIsAdded = !createDefaultRenderInformation(document); if (layoutIsAdded || renderIsAdded) return 0; @@ -126,7 +94,7 @@ namespace LIBSBMLNETWORK_CPP_NAMESPACE { return -1; } - int align(SBMLDocument* document, std::set > nodesSet, const std::string& alignment, const bool ignoreLockedNodes) { + int align(SBMLDocument* document, std::set > nodesSet, const std::string& alignment, const bool ignoreFixedPositionNodes) { if (nodesSet.size() > 1) { std::vector allGraphicalObjects; for (std::set >::const_iterator nodeIt = nodesSet.cbegin(); nodeIt != nodesSet.cend(); nodeIt++) { @@ -136,7 +104,7 @@ namespace LIBSBMLNETWORK_CPP_NAMESPACE { } allGraphicalObjects.push_back(graphicalObjects[nodeIt->second]); } - alignGraphicalObjects(getLayout(document), allGraphicalObjects, alignment, ignoreLockedNodes); + align_elements_alignGraphicalObjects(getLayout(document), allGraphicalObjects, alignment, ignoreFixedPositionNodes); return updateLayoutCurves(document, getLayout(document)); } @@ -153,7 +121,7 @@ namespace LIBSBMLNETWORK_CPP_NAMESPACE { } allGraphicalObjects.push_back(graphicalObjects[nodeIt->second]); } - distributeGraphicalObjects(getLayout(document), allGraphicalObjects, direction, spacing); + align_elements_distributeGraphicalObjects(getLayout(document), allGraphicalObjects, direction, spacing); return updateLayoutCurves(document, getLayout(document)); } diff --git a/src/libsbmlnetwork_sbmldocument.h b/src/libsbmlnetwork_sbmldocument.h index 3a55453..7dd5115 100644 --- a/src/libsbmlnetwork_sbmldocument.h +++ b/src/libsbmlnetwork_sbmldocument.h @@ -76,10 +76,10 @@ LIBSBMLNETWORK_EXTERN bool isSetModel(SBMLDocument* document); /// @param document a pointer to the SBMLDocument object. /// @param maxNumConnectedEdges the maximum number of connected edges to a node in the autolayout algorithm. /// @param useNameAsTextLabel a variable that determines whether to use the name of the species/reaction as the text label in the autolayout algorithm. -/// @param resetLockedElements a variable that determines whether to reset the locked elements in the autolayout algorithm. -/// @param lockedNodesSet a set of locked nodes and their graphical object indices to be used in the autolayout algorithm. +/// @param resetFixedPositionElements a variable that determines whether to reset the fixed position elements in the autolayout algorithm. +/// @param fixedPositionNodesSet a set of fixed position nodes and their graphical object indices to be used in the autolayout algorithm. /// @return integer value indicating success/failure of the function. -LIBSBMLNETWORK_EXTERN int autolayout(SBMLDocument* document, const int maxNumConnectedEdges = 3, bool useNameAsTextLabel = true, bool resetLockedElements = false, std::set > lockedNodesSet = {}); +LIBSBMLNETWORK_EXTERN int autolayout(SBMLDocument* document, const int maxNumConnectedEdges = 3, bool useNameAsTextLabel = true, bool resetFixedPositionElements = false, std::set > fixedPositionNodesSet = {}); /// @brief Create a Render object and add it to the the SBML document if it does not exist. /// @param document a pointer to the SBMLDocument object. @@ -91,9 +91,9 @@ LIBSBMLNETWORK_EXTERN int autorender(SBMLDocument* document, const int maxNumCon /// @param document a pointer to the SBMLDocument object. /// @param nodes a set of node ids and their graphical object indices to be aligned. /// @param alignment determines how to align the nodes. -/// @param ignoreLockedNodes a variable that determines whether to ignore the locked nodes in the alignment algorithm. +/// @param ignoreFixedPositionNodes a variable that determines whether to ignore the fixed position nodes in the alignment algorithm. /// @return integer value indicating success/failure of the function. -LIBSBMLNETWORK_EXTERN int align(SBMLDocument* document, std::set > nodesSet, const std::string& alignment, const bool ignoreLockedNodes = false); +LIBSBMLNETWORK_EXTERN int align(SBMLDocument* document, std::set > nodesSet, const std::string& alignment, const bool ignoreFixedPositionNodes = false); /// @brief Distribute the nodes position in the SBML document in the given distribution direction. /// @param document a pointer to the SBMLDocument object. diff --git a/src/libsbmlnetwork_sbmldocument_helpers.cpp b/src/libsbmlnetwork_sbmldocument_helpers.cpp deleted file mode 100644 index 7024a42..0000000 --- a/src/libsbmlnetwork_sbmldocument_helpers.cpp +++ /dev/null @@ -1,86 +0,0 @@ -#include "libsbmlnetwork_sbmldocument_helpers.h" -#include "libsbmlnetwork_common.h" -#include "libsbmlnetwork_sbmldocument_layout.h" -#include "libsbmlnetwork_layout_helpers.h" -#include "libsbmlnetwork_sbmldocument_render.h" -#include "libsbmlnetwork_render.h" -#include "libsbmlnetwork_render_helpers.h" -#include "libsbmlnetwork_layout_render.h" - -namespace LIBSBMLNETWORK_CPP_NAMESPACE { - -const std::string getErrorLog(SBase* sBase) { - std::string errorLog = ""; - if (sBase) - errorLog = prepareErrorMessage(getUserData(sBase, "error_log"), errorLog); - - return errorLog; - -} - -void clearErrorLog(SBase* sBase) { - if (sBase) - setUserData(sBase, "error_log", ""); -} - -void addErrorToLog(SBase* sbase, const std::string& errorMessage) { - if (sbase && !errorMessage.empty()) { - std::string errorLog = getUserData(sbase, "error_log"); - if (!errorLog.empty()) - errorLog += "\n"; - errorLog += errorMessage; - setUserData(sbase, "error_log", errorLog); - } -} - -const std::string prepareErrorMessage(const std::string& errorMessage, const std::string& errorLog) { - std::string preparedErrorMessage = ""; - if (!errorMessage.empty()) { - if (!errorLog.empty()) - preparedErrorMessage += "\n"; - - preparedErrorMessage += errorMessage; - } - - return preparedErrorMessage; -} - -const std::string getUserData(SBase* sBase, const std::string& key) { - if (sBase->isSetUserData()) { - auto userData = (std::map*)sBase->getUserData(); - if (userData->find(key) != userData->end()) - return (*userData)[key]; - } - - return ""; -} - - -void setUserData(SBase* sBase, const std::string& key, const std::string& value) { - if (!sBase->isSetUserData()) - sBase->setUserData(new std::map()); - auto userData = (std::map*)sBase->getUserData(); - (*userData)[key] = value; -} - -void freeUserData(SBMLDocument* document) { - if (document) { - ListOfLayouts* listOfLayouts = getListOfLayouts(document); - freeUserData(listOfLayouts); - const int numLayouts = getNumLayouts(document); - for (int i = 0; i < numLayouts; i++) - freeUserData(getLayout(document, i)); - } -} - -void freeUserData(SBase* sBase) { - if (sBase) { - if (sBase->isSetUserData()) { - auto userData = (std::map*)sBase->getUserData(); - delete userData; - sBase->unsetUserData(); - } - } -} - -} \ No newline at end of file diff --git a/src/libsbmlnetwork_sbmldocument_helpers.h b/src/libsbmlnetwork_sbmldocument_helpers.h deleted file mode 100644 index 8771389..0000000 --- a/src/libsbmlnetwork_sbmldocument_helpers.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef __LIBSBMLNETWORK_SBMLDOCUMENT_HELPERS_H_ -#define __LIBSBMLNETWORK_SBMLDOCUMENT_HELPERS_H_ - -#include "libsbmlnetwork_sbmldocument.h" - -namespace LIBSBMLNETWORK_CPP_NAMESPACE { - -const std::string getErrorLog(SBase* sBase); - -void clearErrorLog(SBase* sBase); - -void addErrorToLog(SBase* sbase, const std::string& errorMessage); - -const std::string prepareErrorMessage(const std::string& errorMessage, const std::string& errorLog); - -const std::string getUserData(SBase* sbase, const std::string& key); - -void setUserData(SBase* sBase, const std::string& key, const std::string& value); - -void freeUserData(SBMLDocument* document); - -void freeUserData(SBase* sbase); - -} - -#endif \ No newline at end of file diff --git a/src/libsbmlnetwork_sbmldocument_layout.cpp b/src/libsbmlnetwork_sbmldocument_layout.cpp index b55a568..54a5834 100644 --- a/src/libsbmlnetwork_sbmldocument_layout.cpp +++ b/src/libsbmlnetwork_sbmldocument_layout.cpp @@ -2,7 +2,15 @@ #include "libsbmlnetwork_sbmldocument.h" #include "libsbmlnetwork_layout.h" #include "libsbmlnetwork_layout_helpers.h" -#include "autolayout/libsbmlnetwork_autolayout.h" +#include "features/set_layout_features/libsbmlnetwork_set_layout_features.h" +#include "features/update_curves/libsbmlnetwork_update_curves.h" +#include "features/autolayout/libsbmlnetwork_autolayout.h" +#include "features/user_data/libsbmlnetwork_user_data.h" +#include "features/defaults/libsbmlnetwork_defaults_layout.h" +#include "features/alias_elements/libsbmlnetwork_alias_species.h" +#include "features/alias_elements/libsbmlnetwork_alias_reaction.h" +#include "features/hide_elements/libsbmlnetwork_hide_species.h" +#include "features/fix_elements/libsbmlnetwork_fix_element_position.h" namespace LIBSBMLNETWORK_CPP_NAMESPACE { @@ -58,55 +66,16 @@ int removeAllLayouts(SBMLDocument* document) { } int setDefaultLayoutFeatures(SBMLDocument* document, Layout* layout, const int maxNumConnectedEdges) { - if (document && layout) { - setDefaultLayoutId(layout); - setDefaultLayoutDimensions(layout); - Model* model = document->getModel(); - if (model) { - clearGraphicalObjects(layout); - setCompartmentGlyphs(model, layout); - setReactionGlyphs(model, layout, maxNumConnectedEdges); - setTextGlyphs(layout); - return 0; - } - } - - return -1; + return set_layout_features_setDefaultLayoutFeatures(document, layout, maxNumConnectedEdges); } int setDefaultLayoutLocations(SBMLDocument* document, Layout* layout, const int maxNumConnectedEdges, bool useNameAsTextLabel, - bool resetLockedElements, const std::set > lockedNodesSet) { - if (document && layout) { - setDefaultLayoutId(layout); - setDefaultLayoutDimensions(layout); - Model* model = document->getModel(); - if (model) { - lockGraphicalObjects(layout, lockedNodesSet, resetLockedElements); - std::vector> userData = getUserData(layout); - clearGraphicalObjects(layout); - setCompartmentGlyphs(model, layout, userData); - setReactionGlyphs(model, layout, maxNumConnectedEdges, userData); - locateGlyphs(model, layout, useNameAsTextLabel); - setTextGlyphs(layout); - return 0; - } - } - - return -1; + bool resetFixedPositionElements, const std::set > fixedPositionNodesSet) { + return set_layout_features_setDefaultLayoutLocations(document, layout, maxNumConnectedEdges, useNameAsTextLabel, resetFixedPositionElements, fixedPositionNodesSet); } int updateLayoutCurves(SBMLDocument* document, Layout* layout) { - if (document && layout) { - Model* model = document->getModel(); - if (model) { - clearReactionTextGlyphs(layout); - locateReactions(model, layout, true); - setReactionTextGlyphs(layout); - return 0; - } - } - - return -1; + return update_curves_updateLayoutCurves(document, layout); } int createDefaultLayoutFeatures(SBMLDocument* document, const int maxNumConnectedEdges) { @@ -118,34 +87,34 @@ int createDefaultLayoutFeatures(SBMLDocument* document, const int maxNumConnecte } int createDefaultLayoutLocations(SBMLDocument* document, const int maxNumConnectedEdges, bool useNameAsTextLabel, - bool resetLockedElements, const std::set > lockedNodesSet) { + bool resetFixedPositionElements, const std::set > fixedPositionNodesSet) { Layout* layout = getLayout(document); if (!layout) layout = createLayout(document); - return setDefaultLayoutLocations(document, layout, maxNumConnectedEdges, useNameAsTextLabel, resetLockedElements, lockedNodesSet); + return setDefaultLayoutLocations(document, layout, maxNumConnectedEdges, useNameAsTextLabel, resetFixedPositionElements, fixedPositionNodesSet); } int createAliasSpeciesGlyph(SBMLDocument* document, const std::string& speciesId, const std::string& reactionId, unsigned int reactionGlyphIndex) { - if (!createAliasSpeciesGlyph(getLayout(document), speciesId, getReactionGlyph(document, reactionId, reactionGlyphIndex))) + if (!alias_element_createAliasSpeciesGlyph(getLayout(document), speciesId, getReactionGlyph(document, reactionId, reactionGlyphIndex))) return updateLayoutCurves(document, getLayout(document)); return -1; } int createAliasSpeciesGlyph(SBMLDocument* document, unsigned int layoutIndex, const std::string& speciesId, const std::string& reactionId, unsigned int reactionGlyphIndex) { - if (!createAliasSpeciesGlyph(getLayout(document, layoutIndex), speciesId, getReactionGlyph(document, reactionId, reactionGlyphIndex))) + if (!alias_element_createAliasSpeciesGlyph(getLayout(document, layoutIndex), speciesId, getReactionGlyph(document, reactionId, reactionGlyphIndex))) return updateLayoutCurves(document, getLayout(document, layoutIndex)); return -1; } int createAliasReactionGlyph(SBMLDocument* document, const std::string& reactionId) { - return createAliasReactionGlyph(document, getLayout(document), getReactionGlyph(document, reactionId)); + return alias_element_createAliasReactionGlyph(document, getLayout(document), getReactionGlyph(document, reactionId)); } int createAliasReactionGlyph(SBMLDocument* document, unsigned int layoutIndex, const std::string& reactionId) { - return createAliasReactionGlyph(document, getLayout(document, layoutIndex), getReactionGlyph(document, reactionId)); + return alias_element_createAliasReactionGlyph(document, getLayout(document, layoutIndex), getReactionGlyph(document, reactionId)); } int setSpeciesGlyphIndexInReactionGlyph(SBMLDocument* document, const std::string& speciesId, const std::string& reactionId, const unsigned int index) { @@ -177,14 +146,14 @@ int setSpeciesGlyphIndexInReactionGlyph(SBMLDocument* document, unsigned int lay } int makeSpeciesGlyphVisible(SBMLDocument* document, const std::string& speciesId, const std::string& reactionId, unsigned int reactionGlyphIndex, bool visible) { - if (!makeSpeciesGlyphVisible(getReactionGlyph(document, reactionId, reactionGlyphIndex), speciesId, visible)) + if (!hide_elements_makeSpeciesGlyphVisible(getReactionGlyph(document, reactionId, reactionGlyphIndex), speciesId, visible)) return setDefaultLayoutLocations(document, getLayout(document)); return -1; } int makeSpeciesGlyphVisible(SBMLDocument* document, unsigned int layoutIndex, const std::string& speciesId, const std::string& reactionId, unsigned int reactionGlyphIndex, bool visible) { - if (!makeSpeciesGlyphVisible(getReactionGlyph(document, layoutIndex, reactionId, reactionGlyphIndex), speciesId, visible)) + if (!hide_elements_makeSpeciesGlyphVisible(getReactionGlyph(document, layoutIndex, reactionId, reactionGlyphIndex), speciesId, visible)) return setDefaultLayoutLocations(document, getLayout(document, layoutIndex)); return -1; @@ -192,7 +161,7 @@ int makeSpeciesGlyphVisible(SBMLDocument* document, unsigned int layoutIndex, co int makeSpeciesGlyphsVisible(SBMLDocument* document, const std::set >& species, bool visible) { if (document && document->isSetModel()) { - if (!makeSpeciesGlyphsVisible(document->getModel(), getLayout(document), species, visible)) + if (!hide_elements_makeSpeciesGlyphsVisible(document->getModel(), getLayout(document), species, visible)) return setDefaultLayoutLocations(document, getLayout(document)); } @@ -202,7 +171,7 @@ int makeSpeciesGlyphsVisible(SBMLDocument* document, const std::set >& species, bool visible) { if (document && document->isSetModel()) { - if (!makeSpeciesGlyphsVisible(document->getModel(), getLayout(document, layoutIndex), species, visible)) + if (!hide_elements_makeSpeciesGlyphsVisible(document->getModel(), getLayout(document, layoutIndex), species, visible)) return setDefaultLayoutLocations(document, getLayout(document, layoutIndex)); } @@ -1206,7 +1175,7 @@ int setCompartmentDimensionWidth(SBMLDocument* document, unsigned int layoutInde } const double getSpeciesDimensionWidth() { - return getSpeciesDefaultWidth(); + return defaults_getSpeciesDefaultWidth(); } @@ -1222,7 +1191,7 @@ int setSpeciesDimensionWidth(SBMLDocument* document, unsigned int layoutIndex, c } const double getReactionDimensionWidth() { - return getReactionDefaultWidth(); + return defaults_getReactionDefaultWidth(); } int setReactionDimensionWidth(SBMLDocument* document, unsigned int layoutIndex, const double& width, bool updateCurves) { @@ -1300,7 +1269,7 @@ int setCompartmentDimensionHeight(SBMLDocument* document, unsigned int layoutInd } const double getSpeciesDimensionHeight() { - return getSpeciesDefaultHeight(); + return defaults_getSpeciesDefaultHeight(); } int setSpeciesDimensionHeight(SBMLDocument* document, unsigned int layoutIndex, const double& height, bool updateCurves) { @@ -1315,7 +1284,7 @@ int setSpeciesDimensionHeight(SBMLDocument* document, unsigned int layoutIndex, } const double getReactionDimensionHeight() { - return getReactionDefaultHeight(); + return defaults_getReactionDefaultHeight(); } int setReactionDimensionHeight(SBMLDocument* document, unsigned int layoutIndex, const double& height, bool updateCurves) { diff --git a/src/libsbmlnetwork_sbmldocument_layout.h b/src/libsbmlnetwork_sbmldocument_layout.h index b89588d..568c28f 100644 --- a/src/libsbmlnetwork_sbmldocument_layout.h +++ b/src/libsbmlnetwork_sbmldocument_layout.h @@ -49,21 +49,21 @@ LIBSBMLNETWORK_EXTERN int removeAllLayouts(SBMLDocument* document); /// @param layout a pointer to the Layout object. /// @param maxNumConnectedEdges the maximum number of connected edges before creating an alias SpeciesGlyph. /// @param useNameAsTextLabel a variable that determines whether to use the name of the model entities as text labels in the autolayout algorithm. -/// @param resetLockedElements a variable that determines whether to reset the locked elements in the autolayout algorithm. -/// @param lockedNodesSet a set of ids of the model entities and the graphical objects indices that are going to be locked in the autolayout algorithm. +/// @param resetFixedPositionElements a variable that determines whether to reset the fixed position elements in the autolayout algorithm. +/// @param fixedPositionNodesSet a set of ids of the model entities and the graphical objects indices that are going to be have fixed position in the autolayout algorithm. /// @return integer value indicating success/failure of the function. LIBSBMLNETWORK_EXTERN int setDefaultLayoutLocations(SBMLDocument* document, Layout* layout, const int maxNumConnectedEdges = 3, bool useNameAsTextLabel = true, - bool resetLockedElements = false, const std::set > lockedNodesSet = {}); + bool resetFixedPositionElements = false, const std::set > fixedPositionNodesSet = {}); /// @brief Create a Layout object, add it to list of layouts of the SBML document, set all the necessary features for it, and apply autolayout algorithm. /// @param document a pointer to the SBMLDocument object. /// @param maxNumConnectedEdges the maximum number of connected edges before creating an alias SpeciesGlyph. /// @param useNameAsTextLabel a variable that determines whether to use the name of the model entities as text labels in the autolayout algorithm. -/// @param resetLockedElements a variable that determines whether to reset the locked elements in the autolayout algorithm. -/// @param lockedNodeIds a set of ids of the model entities and their graphical objects indices that are going to be locked in the autolayout algorithm. +/// @param resetFixedPositionElements a variable that determines whether to reset the fixed position elements in the autolayout algorithm. +/// @param fixedPositionNodeIds a set of ids of the model entities and their graphical objects indices that are going to have fixed position in the autolayout algorithm. /// @return integer value indicating success/failure of the function. LIBSBMLNETWORK_EXTERN int createDefaultLayoutLocations(SBMLDocument* document, const int maxNumConnectedEdges = 3, bool useNameAsTextLabel = true, - bool resetLockedElements = false, const std::set > lockedNodesSet = {}); + bool resetFixedPositionElements = false, const std::set > fixedPositionNodesSet = {}); /// @brief Create a Layout object, add it to list of layouts of the SBML document, and set all the necessary features for it. /// @param document a pointer to the SBMLDocument object. @@ -71,7 +71,7 @@ LIBSBMLNETWORK_EXTERN int createDefaultLayoutLocations(SBMLDocument* document, c /// @return integer value indicating success/failure of the function. LIBSBMLNETWORK_EXTERN int createDefaultLayoutFeatures(SBMLDocument* document, const int maxNumConnectedEdges = 3); -/// @brief lock all the species and reaction nodes in the layout and apply autolayout +/// @brief fix the position of all the species and reaction nodes in the layout and apply autolayout /// @param document a pointer to the SBMLDocument object. /// @param layout a pointer to the Layout object. /// @param updatedGraphicalObject a set of the ids of the GraphicalObject objects the position of which has been updated recently. @@ -1947,7 +1947,7 @@ LIBSBMLNETWORK_EXTERN const double getPositionX(SBMLDocument* document, unsigned /// @param document a pointer to the SBMLDocument object. /// @param id the id of the model entity the GraphicalObject object associated with it to be returned. /// @param x a double value to use as the value of the "x" attribute of the bounding box of this GraphicalObject object. -/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with locked nodes) should be adjusted. Default 'true'. +/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with fixed position nodes) should be adjusted. Default 'true'. /// @return integer value indicating success/failure of the function. LIBSBMLNETWORK_EXTERN int setPositionX(SBMLDocument* document, const std::string& id, const double& x, bool updateCurves = true); @@ -1957,7 +1957,7 @@ LIBSBMLNETWORK_EXTERN int setPositionX(SBMLDocument* document, const std::string /// @param layoutIndex the index number of the Layout to return. /// @param id the id of the model entity the GraphicalObject object associated with it to be returned. /// @param x a double value to use as the value of the "x" attribute of the bounding box of this GraphicalObject object. -/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with locked nodes) should be adjusted. Default 'true'. +/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with fixed position nodes) should be adjusted. Default 'true'. /// @return integer value indicating success/failure of the function. LIBSBMLNETWORK_EXTERN int setPositionX(SBMLDocument* document, unsigned int layoutIndex, const std::string& id, const double& x, bool updateCurves = true); @@ -1967,7 +1967,7 @@ LIBSBMLNETWORK_EXTERN int setPositionX(SBMLDocument* document, unsigned int layo /// @param layoutIndex the index number of the Layout to return. /// @param id the id of the model entity the GraphicalObject object associated with it to be returned. /// @param x a double value to use as the value of the "x" attribute of the bounding box of this GraphicalObject object. -/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with locked nodes) should be adjusted. Default 'true'. +/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with fixed position nodes) should be adjusted. Default 'true'. /// @return integer value indicating success/failure of the function. LIBSBMLNETWORK_EXTERN int setPositionX(SBMLDocument* document, const std::string& id, unsigned int graphicalObjectIndex, const double& x, bool updateCurves = true); @@ -1978,7 +1978,7 @@ LIBSBMLNETWORK_EXTERN int setPositionX(SBMLDocument* document, const std::string /// @param id the id of the model entity the GraphicalObject object associated with it to be returned. /// @param graphicalObjectIndex the index of the GraphicalObject to return. /// @param x a double value to use as the value of the "x" attribute of the bounding box of this GraphicalObject object. -/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with locked nodes) should be adjusted. Default 'true'. +/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with fixed position nodes) should be adjusted. Default 'true'. /// @return integer value indicating success/failure of the function. LIBSBMLNETWORK_EXTERN int setPositionX(SBMLDocument* document, unsigned int layoutIndex, const std::string& id, unsigned int graphicalObjectIndex, const double& x, bool updateCurves = true); @@ -2004,7 +2004,7 @@ LIBSBMLNETWORK_EXTERN const double getPositionY(SBMLDocument* document, unsigned /// @param document a pointer to the SBMLDocument object. /// @param id the id of the model entity the GraphicalObject object associated with it to be returned. /// @param y a double value to use as the value of the "y" attribute of the bounding box of this GraphicalObject object. -/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with locked nodes) should be adjusted. Default 'true'. +/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with fixed position nodes) should be adjusted. Default 'true'. /// @return integer value indicating success/failure of the function. LIBSBMLNETWORK_EXTERN int setPositionY(SBMLDocument* document, const std::string& id, const double& y, bool updateCurves = true); @@ -2014,7 +2014,7 @@ LIBSBMLNETWORK_EXTERN int setPositionY(SBMLDocument* document, const std::string /// @param layoutIndex the index number of the Layout to return. /// @param id the id of the model entity the GraphicalObject object associated with it to be returned. /// @param y a double value to use as the value of the "y" attribute of the bounding box of this GraphicalObject object. -/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with locked nodes) should be adjusted. Default 'true'. +/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with fixed position nodes) should be adjusted. Default 'true'. /// @return integer value indicating success/failure of the function. LIBSBMLNETWORK_EXTERN int setPositionY(SBMLDocument* document, unsigned int layoutIndex, const std::string& id, const double& y, bool updateCurves = true); @@ -2024,7 +2024,7 @@ LIBSBMLNETWORK_EXTERN int setPositionY(SBMLDocument* document, unsigned int layo /// @param layoutIndex the index number of the Layout to return. /// @param id the id of the model entity the GraphicalObject object associated with it to be returned. /// @param y a double value to use as the value of the "y" attribute of the bounding box of this GraphicalObject object. -/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with locked nodes) should be adjusted. Default 'true'. +/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with fixed position nodes) should be adjusted. Default 'true'. /// @return integer value indicating success/failure of the function. LIBSBMLNETWORK_EXTERN int setPositionY(SBMLDocument* document, const std::string& id, unsigned int graphicalObjectIndex, const double& y, bool updateCurves = true); @@ -2035,7 +2035,7 @@ LIBSBMLNETWORK_EXTERN int setPositionY(SBMLDocument* document, const std::string /// @param id the id of the model entity the GraphicalObject object associated with it to be returned. /// @param graphicalObjectIndex the index of the GraphicalObject to return. /// @param y a double value to use as the value of the "y" attribute of the bounding box of this GraphicalObject object. -/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with locked nodes) should be adjusted. Default 'true'. +/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with fixed position nodes) should be adjusted. Default 'true'. /// @return integer value indicating success/failure of the function. LIBSBMLNETWORK_EXTERN int setPositionY(SBMLDocument* document, unsigned int layoutIndex, const std::string& id, unsigned int graphicalObjectIndex, const double& y, bool updateCurves = true); @@ -2045,7 +2045,7 @@ LIBSBMLNETWORK_EXTERN int setPositionY(SBMLDocument* document, unsigned int layo /// @param id the id of the model entity the GraphicalObject object associated with it to be returned. /// @param x a double value to use as the value of the "x" attribute of the bounding box of this GraphicalObject object. /// @param y a double value to use as the value of the "y" attribute of the bounding box of this GraphicalObject object. -/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with locked nodes) should be adjusted. Default 'true'. +/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with fixed position nodes) should be adjusted. Default 'true'. /// @return integer value indicating success/failure of the function. LIBSBMLNETWORK_EXTERN int setPosition(SBMLDocument* document, const std::string& id, const double& x, const double& y, bool updateCurves = true); @@ -2056,7 +2056,7 @@ LIBSBMLNETWORK_EXTERN int setPosition(SBMLDocument* document, const std::string& /// @param id the id of the model entity the GraphicalObject object associated with it to be returned. /// @param x a double value to use as the value of the "x" attribute of the bounding box of this GraphicalObject object. /// @param y a double value to use as the value of the "y" attribute of the bounding box of this GraphicalObject object. -/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with locked nodes) should be adjusted. Default 'true'. +/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with fixed position nodes) should be adjusted. Default 'true'. /// @return integer value indicating success/failure of the function. LIBSBMLNETWORK_EXTERN int setPosition(SBMLDocument* document, unsigned int layoutIndex, const std::string& id, const double& x, const double& y, bool updateCurves = true); @@ -2068,7 +2068,7 @@ LIBSBMLNETWORK_EXTERN int setPosition(SBMLDocument* document, unsigned int layou /// @param graphicalObjectIndex the index of the GraphicalObject to return. /// @param x a double value to use as the value of the "x" attribute of the bounding box of this GraphicalObject object. /// @param y a double value to use as the value of the "y" attribute of the bounding box of this GraphicalObject object. -/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with locked nodes) should be adjusted. Default 'true'. +/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with fixed position nodes) should be adjusted. Default 'true'. /// @return integer value indicating success/failure of the function. LIBSBMLNETWORK_EXTERN int setPosition(SBMLDocument* document, const std::string& id, unsigned int graphicalObjectIndex, const double& x, const double& y, bool updateCurves = true); @@ -2080,7 +2080,7 @@ LIBSBMLNETWORK_EXTERN int setPosition(SBMLDocument* document, const std::string& /// @param graphicalObjectIndex the index of the GraphicalObject to return. /// @param x a double value to use as the value of the "x" attribute of the bounding box of this GraphicalObject object. /// @param y a double value to use as the value of the "y" attribute of the bounding box of this GraphicalObject object. -/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with locked nodes) should be adjusted. Default 'true'. +/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with fixed position nodes) should be adjusted. Default 'true'. /// @return integer value indicating success/failure of the function. LIBSBMLNETWORK_EXTERN int setPosition(SBMLDocument* document, unsigned int layoutIndex, const std::string& id, unsigned int graphicalObjectIndex, const double& x, const double& y, bool updateCurves = true); @@ -2106,7 +2106,7 @@ LIBSBMLNETWORK_EXTERN const double getDimensionWidth(SBMLDocument* document, uns /// @param document a pointer to the SBMLDocument object. /// @param id the id of the model entity the GraphicalObject object associated with it to be returned. /// @param width a double value to use as the value of the "width" attribute of the bounding box of this GraphicalObject object. -/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with locked nodes) should be adjusted. Default 'true'. +/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with fixed position nodes) should be adjusted. Default 'true'. /// @return integer value indicating success/failure of the function. LIBSBMLNETWORK_EXTERN int setDimensionWidth(SBMLDocument* document, const std::string& id, const double& width, bool updateCurves = true); @@ -2116,7 +2116,7 @@ LIBSBMLNETWORK_EXTERN int setDimensionWidth(SBMLDocument* document, const std::s /// @param layoutIndex the index number of the Layout to return. /// @param id the id of the model entity the GraphicalObject object associated with it to be returned. /// @param width a double value to use as the value of the "width" attribute of the bounding box of this GraphicalObject object. -/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with locked nodes) should be adjusted. Default 'true'. +/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with fixed position nodes) should be adjusted. Default 'true'. /// @return integer value indicating success/failure of the function. LIBSBMLNETWORK_EXTERN int setDimensionWidth(SBMLDocument* document, unsigned int layoutIndex, const std::string& id, const double& width, bool updateCurves = true); @@ -2126,7 +2126,7 @@ LIBSBMLNETWORK_EXTERN int setDimensionWidth(SBMLDocument* document, unsigned int /// @param id the id of the model entity the GraphicalObject object associated with it to be returned. /// @param graphicalObjectIndex the index of the GraphicalObject to return. /// @param width a double value to use as the value of the "width" attribute of the bounding box of this GraphicalObject object. -/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with locked nodes) should be adjusted. Default 'true'. +/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with fixed position nodes) should be adjusted. Default 'true'. /// @return integer value indicating success/failure of the function. LIBSBMLNETWORK_EXTERN int setDimensionWidth(SBMLDocument* document, const std::string& id, unsigned int graphicalObjectIndex, const double& width, bool updateCurves = true); @@ -2137,7 +2137,7 @@ LIBSBMLNETWORK_EXTERN int setDimensionWidth(SBMLDocument* document, const std::s /// @param id the id of the model entity the GraphicalObject object associated with it to be returned. /// @param graphicalObjectIndex the index of the GraphicalObject to return. /// @param width a double value to use as the value of the "width" attribute of the bounding box of this GraphicalObject object. -/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with locked nodes) should be adjusted. Default 'true'. +/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with fixed position nodes) should be adjusted. Default 'true'. /// @return integer value indicating success/failure of the function. LIBSBMLNETWORK_EXTERN int setDimensionWidth(SBMLDocument* document, unsigned int layoutIndex, const std::string& id, unsigned int graphicalObjectIndex, const double& width, bool updateCurves = true); @@ -2145,7 +2145,7 @@ LIBSBMLNETWORK_EXTERN int setDimensionWidth(SBMLDocument* document, unsigned int /// @param document a pointer to the SBMLDocument object. /// @param layoutIndex the index number of the Layout to return. /// @param width a double value to use as the value of the "width" attribute of the bounding box of all the CompartmentGlyph objects. -/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with locked nodes) should be adjusted. Default 'true'. +/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with fixed position nodes) should be adjusted. Default 'true'. /// @return integer value indicating success/failure of the function. LIBSBMLNETWORK_EXTERN int setCompartmentDimensionWidth(SBMLDocument* document, unsigned int layoutIndex, const double& width, bool updateCurves = true); @@ -2157,7 +2157,7 @@ LIBSBMLNETWORK_EXTERN const double getSpeciesDimensionWidth(); /// @param document a pointer to the SBMLDocument object. /// @param layoutIndex the index number of the Layout to return. /// @param width a double value to use as the value of the "width" attribute of the bounding box of all the SpeciesGlyph objects. -/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with locked nodes) should be adjusted. Default 'true'. +/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with fixed position nodes) should be adjusted. Default 'true'. /// @return integer value indicating success/failure of the function. LIBSBMLNETWORK_EXTERN int setSpeciesDimensionWidth(SBMLDocument* document, unsigned int layoutIndex, const double& width, bool updateCurves = true); @@ -2169,7 +2169,7 @@ LIBSBMLNETWORK_EXTERN const double getReactionDimensionWidth(); /// @param document a pointer to the SBMLDocument object. /// @param layoutIndex the index number of the Layout to return. /// @param width a double value to use as the value of the "width" attribute of the bounding box of all the ReactionGlyph objects. -/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with locked nodes) should be adjusted. Default 'true'. +/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with fixed position nodes) should be adjusted. Default 'true'. /// @return integer value indicating success/failure of the function. LIBSBMLNETWORK_EXTERN int setReactionDimensionWidth(SBMLDocument* document, unsigned int layoutIndex, const double& width, bool updateCurves = true); @@ -2195,7 +2195,7 @@ LIBSBMLNETWORK_EXTERN const double getDimensionHeight(SBMLDocument* document, un /// @param document a pointer to the SBMLDocument object. /// @param id the id of the model entity the GraphicalObject object associated with it to be returned. /// @param height a double value to use as the value of the "height" attribute of the bounding box of this GraphicalObject object. -/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with locked nodes) should be adjusted. Default 'true'. +/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with fixed position nodes) should be adjusted. Default 'true'. /// @return integer value indicating success/failure of the function. LIBSBMLNETWORK_EXTERN int setDimensionHeight(SBMLDocument* document, const std::string& id, const double& height, bool updateCurves = true); @@ -2205,7 +2205,7 @@ LIBSBMLNETWORK_EXTERN int setDimensionHeight(SBMLDocument* document, const std:: /// @param layoutIndex the index number of the Layout to return. /// @param id the id of the model entity the GraphicalObject object associated with it to be returned. /// @param height a double value to use as the value of the "height" attribute of the bounding box of this GraphicalObject object. -/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with locked nodes) should be adjusted. Default 'true'. +/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with fixed position nodes) should be adjusted. Default 'true'. /// @return integer value indicating success/failure of the function. LIBSBMLNETWORK_EXTERN int setDimensionHeight(SBMLDocument* document, unsigned int layoutIndex, const std::string& id, const double& height, bool updateCurves = true); @@ -2215,7 +2215,7 @@ LIBSBMLNETWORK_EXTERN int setDimensionHeight(SBMLDocument* document, unsigned in /// @param id the id of the model entity the GraphicalObject object associated with it to be returned. /// @param graphicalObjectIndex the index of the GraphicalObject to return. /// @param height a double value to use as the value of the "height" attribute of the bounding box of this GraphicalObject object. -/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with locked nodes) should be adjusted. Default 'true'. +/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with fixed position nodes) should be adjusted. Default 'true'. /// @return integer value indicating success/failure of the function. LIBSBMLNETWORK_EXTERN int setDimensionHeight(SBMLDocument* document, const std::string& id, unsigned int graphicalObjectIndex, const double& height, bool updateCurves = true); @@ -2226,7 +2226,7 @@ LIBSBMLNETWORK_EXTERN int setDimensionHeight(SBMLDocument* document, const std:: /// @param id the id of the model entity the GraphicalObject object associated with it to be returned. /// @param graphicalObjectIndex the index of the GraphicalObject to return. /// @param height a double value to use as the value of the "height" attribute of the bounding box of this GraphicalObject object. -/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with locked nodes) should be adjusted. Default 'true'. +/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with fixed position nodes) should be adjusted. Default 'true'. /// @return integer value indicating success/failure of the function. LIBSBMLNETWORK_EXTERN int setDimensionHeight(SBMLDocument* document, unsigned int layoutIndex, const std::string& id, unsigned int graphicalObjectIndex, const double& height, bool updateCurves = true); @@ -2234,7 +2234,7 @@ LIBSBMLNETWORK_EXTERN int setDimensionHeight(SBMLDocument* document, unsigned in /// @param document a pointer to the SBMLDocument object. /// @param layoutIndex the index number of the Layout to return. /// @param height a double value to use as the value of the "height" attribute of the bounding box of all the CompartmentGlyph objects. -/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with locked nodes) should be adjusted. Default 'true'. +/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with fixed position nodes) should be adjusted. Default 'true'. /// @return integer value indicating success/failure of the function. LIBSBMLNETWORK_EXTERN int setCompartmentDimensionHeight(SBMLDocument* document, unsigned int layoutIndex, const double& height, bool updateCurves = true); @@ -2246,7 +2246,7 @@ LIBSBMLNETWORK_EXTERN const double getSpeciesDimensionHeight(); /// @param document a pointer to the SBMLDocument object. /// @param layoutIndex the index number of the Layout to return. /// @param height a double value to use as the value of the "height" attribute of the bounding box of all the SpeciesGlyph objects. -/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with locked nodes) should be adjusted. Default 'true'. +/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with fixed position nodes) should be adjusted. Default 'true'. /// @return integer value indicating success/failure of the function. LIBSBMLNETWORK_EXTERN int setSpeciesDimensionHeight(SBMLDocument* document, unsigned int layoutIndex, const double& height, bool updateCurves = true); @@ -2258,7 +2258,7 @@ LIBSBMLNETWORK_EXTERN const double getReactionDimensionHeight(); /// @param document a pointer to the SBMLDocument object. /// @param layoutIndex the index number of the Layout to return. /// @param height a double value to use as the value of the "height" attribute of the bounding box of all the ReactionGlyph objects. -/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with locked nodes) should be adjusted. Default 'true'. +/// @param updateCurves a boolean value, indicating whether the rest of the layout curves (with fixed position nodes) should be adjusted. Default 'true'. /// @return integer value indicating success/failure of the function. LIBSBMLNETWORK_EXTERN int setReactionDimensionHeight(SBMLDocument* document, unsigned int layoutIndex, const double& height, bool updateCurves = true); diff --git a/src/libsbmlnetwork_sbmldocument_render.cpp b/src/libsbmlnetwork_sbmldocument_render.cpp index ebfbe37..031f6a4 100644 --- a/src/libsbmlnetwork_sbmldocument_render.cpp +++ b/src/libsbmlnetwork_sbmldocument_render.cpp @@ -5,8 +5,9 @@ #include "libsbmlnetwork_render.h" #include "libsbmlnetwork_render_helpers.h" #include "libsbmlnetwork_layout_helpers.h" -#include "libsbmlnetwork_sbmldocument_helpers.h" -#include "styles/libsbmlnetwork_styles.h" +#include "features/styles/libsbmlnetwork_styles.h" +#include "features/error_log/libsbmlnetwork_error_log.h" +#include "features/defaults/libsbmlnetwork_defaults_render.h" namespace LIBSBMLNETWORK_CPP_NAMESPACE { @@ -66,8 +67,8 @@ int setDefaultGlobalRenderInformationFeatures(SBMLDocument* document, GlobalRend if (document && globalRenderInformation) { globalRenderInformation->setId("libSBMLNetwork_Global_Render"); globalRenderInformation->setBackgroundColor("white"); - addDefaultColors(globalRenderInformation); - addDefaultLineEndings(globalRenderInformation); + defaults_addDefaultColors(globalRenderInformation); + defaults_addDefaultLineEndings(globalRenderInformation); addGlobalStyles(globalRenderInformation); return 0; } @@ -5937,9 +5938,9 @@ int setGeometricShapeType(SBMLDocument* document, GraphicalObject* graphicalObje style = createLocalStyle(document, graphicalObject); if (!setGeometricShapeType(style, shape)) { if (getGlobalRenderInformation(document)) - addColorsOfDefaultGeometricShapes(getGlobalRenderInformation(document)); + defaults_addColorsOfDefaultGeometricShapes(getGlobalRenderInformation(document)); else - addColorsOfDefaultGeometricShapes(document, style); + defaults_addColorsOfDefaultGeometricShapes(document, style); removeCurve(graphicalObject); return 0; } @@ -5955,9 +5956,9 @@ int setGeometricShapeType(SBMLDocument* document, const std::string& attribute, style = createLocalStyle(document, attribute); if (!setGeometricShapeType(style, shape)) { if (getGlobalRenderInformation(document)) - addColorsOfDefaultGeometricShapes(getGlobalRenderInformation(document)); + defaults_addColorsOfDefaultGeometricShapes(getGlobalRenderInformation(document)); else - addColorsOfDefaultGeometricShapes(document, style); + defaults_addColorsOfDefaultGeometricShapes(document, style); removeCurve(getGraphicalObject(document, attribute)); return 0; } @@ -10706,7 +10707,7 @@ const std::string getStyle(SBMLDocument* document, unsigned int renderIndex) { int setStyle(SBMLDocument* document, unsigned int renderIndex, const std::string& styleName) { if (!isValidPredefinedStyleName(styleName)) { - addErrorToLog(document, "The style name is not valid."); + error_log_addErrorToLog(document, "The style name is not valid."); return -1; } std::map styleFeatures = getPredefinedStyleFeatures(styleName);