From 28d61c34732d7e31f8963ad82bb37b40e834fda6 Mon Sep 17 00:00:00 2001 From: adelhpour Date: Fri, 1 Nov 2024 12:22:30 -0700 Subject: [PATCH 1/8] The bug with running the autolayout algorithm with no reactions is fixed --- src/autolayout/libsbmlnetwork_autolayout.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/autolayout/libsbmlnetwork_autolayout.cpp b/src/autolayout/libsbmlnetwork_autolayout.cpp index c709223..0c73bfd 100755 --- a/src/autolayout/libsbmlnetwork_autolayout.cpp +++ b/src/autolayout/libsbmlnetwork_autolayout.cpp @@ -324,7 +324,7 @@ const bool adjustLayoutDimensions(Layout *layout) { double widthGap = desiredWidth - layout->getDimensions()->width(); double desiredHeight = getLayoutDimensionsDesiredHeight(layout); double heightGap = desiredHeight - layout->getDimensions()->height(); - if (widthGap < 0.1 * desiredWidth && heightGap < 0.1 * desiredHeight) { + if (widthGap <= 0.1 * desiredWidth && heightGap <= 0.1 * desiredHeight) { setLayoutDimensionsDesiredWidth(layout, layout->getDimensions()->width()); setLayoutDimensionsDesiredHeight(layout, layout->getDimensions()->height()); return true; From 3820ca904575af3dfe376e2cd1e932ccfae51ab4 Mon Sep 17 00:00:00 2001 From: adelhpour Date: Fri, 1 Nov 2024 13:02:14 -0700 Subject: [PATCH 2/8] The issue with initializing the compartment extents in the autolayout algorithm is fixed --- src/autolayout/libsbmlnetwork_autolayout.cpp | 21 ++++++++++++-------- src/autolayout/libsbmlnetwork_autolayout.h | 6 +++--- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/autolayout/libsbmlnetwork_autolayout.cpp b/src/autolayout/libsbmlnetwork_autolayout.cpp index 0c73bfd..c08b063 100755 --- a/src/autolayout/libsbmlnetwork_autolayout.cpp +++ b/src/autolayout/libsbmlnetwork_autolayout.cpp @@ -28,7 +28,7 @@ void locateGlyphs(Model *model, Layout *layout, const bool &useNameAsTextLabel) autoLayoutAlgorithm->setWidth(layout); autoLayoutAlgorithm->setHeight(layout); autoLayoutAlgorithm->apply(); - updateCompartmentExtents(model, layout); + updateCompartmentsExtents(model, layout); updateLayoutDimensions(layout); delete autoLayoutAlgorithm; if (!adjustLayoutDimensions(layout)) { @@ -57,7 +57,7 @@ void locateReactions(Model *model, Layout *layout, const bool &useNameAsTextLabe autoLayoutAlgorithm->setWidth(layout); autoLayoutAlgorithm->setHeight(layout); autoLayoutAlgorithm->apply(); - updateCompartmentExtents(model, layout); + updateCompartmentsExtents(model, layout); updateLayoutDimensions(layout); delete autoLayoutAlgorithm; } @@ -189,12 +189,13 @@ initializeCompartmentGlyphExtents(BoundingBox *compartmentGlyphBoundingBox, Boun compartmentGlyphBoundingBox->setHeight(speciesGlyphBoundingBox->height() + 2 * padding); } -void updateCompartmentExtents(Model *model, Layout *layout) { - updateCompartmentExtentsUsingItsElementsExtents(model, layout); - updateCompartmentExtentsUsingItsPresetAttributes(layout); +void updateCompartmentsExtents(Model *model, Layout *layout) { + updateCompartmentsExtentsUsingTheirElementsExtents(model, layout); + updateCompartmentsExtentsUsingTheirPresetAttributes(layout); } -void updateCompartmentExtentsUsingItsElementsExtents(Model *model, Layout *layout) { +void updateCompartmentsExtentsUsingTheirElementsExtents(Model *model, Layout *layout) { + std::vector extentsInitializedCompartmentGlyphIds; for (int i = 0; i < layout->getNumSpeciesGlyphs(); i++) { Compartment *compartment = findSpeciesGlyphCompartment(model, layout->getSpeciesGlyph(i)); if (compartment) { @@ -202,9 +203,13 @@ void updateCompartmentExtentsUsingItsElementsExtents(Model *model, Layout *layou layout, compartment->getId()); for (int j = 0; j < compartmentGlyphs.size(); j++) { CompartmentGlyph *compartmentGlyph = compartmentGlyphs.at(j); - if (i == 0) + if (std::find(extentsInitializedCompartmentGlyphIds.begin(), + extentsInitializedCompartmentGlyphIds.end(), compartmentGlyph->getId()) == + extentsInitializedCompartmentGlyphIds.end()) { initializeCompartmentGlyphExtents(compartmentGlyph->getBoundingBox(), layout->getSpeciesGlyph(i)->getBoundingBox()); + extentsInitializedCompartmentGlyphIds.push_back(compartmentGlyph->getId()); + } updateCompartmentExtentsUsingItsElementsExtents(compartmentGlyph->getBoundingBox(), layout->getSpeciesGlyph(i)->getBoundingBox()); } @@ -280,7 +285,7 @@ void updateCompartmentExtentsUsingItsElementsExtents(BoundingBox *compartmentGly } } -void updateCompartmentExtentsUsingItsPresetAttributes(Layout *layout) { +void updateCompartmentsExtentsUsingTheirPresetAttributes(Layout *layout) { for (int i = 0; i < layout->getNumCompartmentGlyphs(); i++) { CompartmentGlyph *compartmentGlyph = layout->getCompartmentGlyph(i); if (LIBSBMLNETWORK_CPP_NAMESPACE::getUserData(compartmentGlyph, "locked") == "true") { diff --git a/src/autolayout/libsbmlnetwork_autolayout.h b/src/autolayout/libsbmlnetwork_autolayout.h index 8c9f686..01c39b2 100755 --- a/src/autolayout/libsbmlnetwork_autolayout.h +++ b/src/autolayout/libsbmlnetwork_autolayout.h @@ -50,15 +50,15 @@ void setSpeciesGlyphDimensions(Model *model, SpeciesGlyph* speciesGlyph); void initializeCompartmentGlyphExtents(BoundingBox* compartmentGlyphBoundingBox, BoundingBox* speciesGlyphBoundingBox); -void updateCompartmentExtents(Model *model, Layout *layout); +void updateCompartmentsExtents(Model *model, Layout *layout); -void updateCompartmentExtentsUsingItsElementsExtents(Model *model, Layout *layout); +void updateCompartmentsExtentsUsingTheirElementsExtents(Model *model, Layout *layout); void updateCompartmentExtentsUsingItsElementsExtents(BoundingBox* compartmentGlyphBoundingBox, BoundingBox* speciesGlyphBoundingBox); void updateCompartmentExtentsUsingItsElementsExtents(BoundingBox* compartmentGlyphBoundingBox, Curve* reactionCurve); -void updateCompartmentExtentsUsingItsPresetAttributes(Layout *layout); +void updateCompartmentsExtentsUsingTheirPresetAttributes(Layout *layout); void updateLayoutDimensions(Layout* layout); From dab196baffcb31e514c8755cc333516377486a9d Mon Sep 17 00:00:00 2001 From: adelhpour Date: Mon, 4 Nov 2024 07:59:49 -0800 Subject: [PATCH 3/8] updateLayoutCurves now passes 'true' value as the useNameAsTextLabel value to the locateReactions function --- src/libsbmlnetwork_sbmldocument_layout.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libsbmlnetwork_sbmldocument_layout.cpp b/src/libsbmlnetwork_sbmldocument_layout.cpp index ff8df03..fb4d093 100644 --- a/src/libsbmlnetwork_sbmldocument_layout.cpp +++ b/src/libsbmlnetwork_sbmldocument_layout.cpp @@ -100,7 +100,7 @@ int updateLayoutCurves(SBMLDocument* document, Layout* layout) { Model* model = document->getModel(); if (model) { clearReactionTextGlyphs(layout); - locateReactions(model, layout, false); + locateReactions(model, layout, true); setReactionTextGlyphs(layout); return 0; } From 1dddeb8358c7cce8b7030ec2e445a68af0e4d636 Mon Sep 17 00:00:00 2001 From: adelhpour Date: Tue, 5 Nov 2024 09:27:43 -0800 Subject: [PATCH 4/8] The functions to get/set the id of the geometric shapes in the RenderGroup of the Styles associated with elements are added --- .../python/ctypes/libsbmlnetwork.py.cmake | 36 +++++++++++ src/c_api/libsbmlnetwork_c_api.cpp | 8 +++ src/c_api/libsbmlnetwork_c_api.h | 19 ++++++ src/libsbmlnetwork_render.cpp | 64 +++++++++++++++++++ src/libsbmlnetwork_render.h | 28 ++++++++ src/libsbmlnetwork_sbmldocument_render.cpp | 58 +++++++++++++++++ src/libsbmlnetwork_sbmldocument_render.h | 44 +++++++++++++ 7 files changed, 257 insertions(+) diff --git a/src/bindings/python/ctypes/libsbmlnetwork.py.cmake b/src/bindings/python/ctypes/libsbmlnetwork.py.cmake index 7ddf3e3..8209a25 100644 --- a/src/bindings/python/ctypes/libsbmlnetwork.py.cmake +++ b/src/bindings/python/ctypes/libsbmlnetwork.py.cmake @@ -9145,6 +9145,42 @@ class LibSBMLNetwork: """ return lib.c_api_removeGeometricShape(self.sbml_object, str(id).encode(), geometric_shape_index, graphical_object_index, layout_index) + def getGeometricShapeId(self, id, geometric_shape_index=0, graphical_object_index=0, layout_index=0): + """ + Returns the id of the GeometricShape object with the given index associated with the model entity with the given id in the given SBMLDocument + + :Parameters: + + - id (string): a string that determines the id of the model entity + - geometric_shape_index (int, optional): an integer (default: 0) that determines the index of the GeometricShape object associated with the model entity with the given id in the given SBMLDocument + - graphical_object_index (int, optional): an integer (default: 0) that determines the index of the GraphicalObject in the given SBMLDocument + - layout_index (int, optional): an integer (default: 0) that determines the index of the Layout object in the given SBMLDocument + + :Returns: + + a string that determines the id of the GeometricShape object associated with the model entity with the given id in the given SBMLDocument + """ + lib.c_api_getGeometricShapeId.restype = ctypes.c_char_p + return ctypes.c_char_p(lib.c_api_getGeometricShapeId(self.sbml_object, str(id).encode(), geometric_shape_index, graphical_object_index, layout_index)).value.decode() + + def setGeometricShapeId(self, id, geometric_shape_id, geometric_shape_index=0, graphical_object_index=0, layout_index=0): + """ + Sets the id of the GeometricShape object with the given index associated with the model entity with the given id in the given SBMLDocument + + :Parameters: + + - id (string): a string that determines the id of the model entity + - geometric_shape_id (string): a string that determines the id of the GeometricShape object to be added to the model entity + - geometric_shape_index (int, optional): an integer (default: 0) that determines the index of the GeometricShape object associated with the model entity with the given id in the given SBMLDocument + - graphical_object_index (int, optional): an integer (default: 0) that determines the index of the GraphicalObject in the given SBMLDocument + - layout_index (int, optional): an integer (default: 0) that determines the index of the Layout object in the given SBMLDocument + + :Returns: + + true on success and false if the id of the GeometricShape object could not be set + """ + return lib.c_api_setGeometricShapeId(self.sbml_object, str(id).encode(), str(geometric_shape_id).encode(), geometric_shape_index, graphical_object_index, layout_index) + def getGeometricShapeType(self, id, geometric_shape_index=0, graphical_object_index=0, layout_index=0): """ Returns the type of the GeometricShape object with the given index associated with the model entity with the given id in the given SBMLDocument diff --git a/src/c_api/libsbmlnetwork_c_api.cpp b/src/c_api/libsbmlnetwork_c_api.cpp index 2a168f8..772a38f 100644 --- a/src/c_api/libsbmlnetwork_c_api.cpp +++ b/src/c_api/libsbmlnetwork_c_api.cpp @@ -2422,6 +2422,14 @@ namespace LIBSBMLNETWORK_CPP_NAMESPACE { return setGeometricShapeType(document, getGraphicalObject(document, layoutIndex, id, graphicalObjectIndex), shape); } + const char* c_api_getGeometricShapeId(SBMLDocument* document, const char* id, int geometricShapeIndex, int graphicalObjectIndex, int layoutIndex) { + return strdup(getGeometricShapeId(document, getGraphicalObject(document, layoutIndex, id, graphicalObjectIndex), geometricShapeIndex).c_str()); + } + + int c_api_setGeometricShapeId(SBMLDocument* document, const char* id, const char* geometricShapeId, int geometricShapeIndex, int graphicalObjectIndex, int layoutIndex) { + return setGeometricShapeId(document, getGraphicalObject(document, layoutIndex, id, graphicalObjectIndex), geometricShapeIndex, geometricShapeId); + } + const char* c_api_getCompartmentsGeometricShapeType(SBMLDocument* document) { return strdup(getCompartmentGeometricShapeType(document).c_str()); } diff --git a/src/c_api/libsbmlnetwork_c_api.h b/src/c_api/libsbmlnetwork_c_api.h index 4a57a95..2313d2a 100644 --- a/src/c_api/libsbmlnetwork_c_api.h +++ b/src/c_api/libsbmlnetwork_c_api.h @@ -4765,6 +4765,25 @@ namespace LIBSBMLNETWORK_CPP_NAMESPACE { /// @return integer value indicating success/failure of the function. LIBSBMLNETWORK_EXTERN int c_api_setGeometricShapeType(SBMLDocument* document, const char* id, const char* shape, int graphicalObjectIndex = 0, int layoutIndex = 0); + /// @brief Returns the id of the geometric shape of the RenderGroup of the Style that matches this id of model entity associated with GraphicalObject. + /// @param document a pointer to the SBMLDocument object. + /// @param id the id of a model entity. + /// @param geometricShapeIndex an int representing the index of the Transformation2D to retrieve. + /// @param graphicalObjectIndex the index of the GraphicalObject to return. + /// @param layoutIndex the index number of the Layout to return. + /// @return the id of the geometric shape of the RenderGroup of the Style for this GraphicalObject, or @c "" if the object is @c NULL + LIBSBMLNETWORK_EXTERN const char* c_api_getGeometricShapesId(SBMLDocument* document, const char* id, int geometricShapeIndex = 0, int graphicalObjectIndex = 0, int layoutIndex = 0); + + /// @brief Sets the id of the geometric shape of the RenderGroup of the Style that matches this id of model entity associated with GraphicalObject. + /// @param document a pointer to the SBMLDocument object. + /// @param id the id of a model entity. + /// @param geometricShapeId a string value indicating the id of the geometric shape to be set. + /// @param geometricShapeIndex an int representing the index of the Transformation2D to retrieve. + /// @param graphicalObjectIndex the index of the GraphicalObject to return. + /// @param layoutIndex the index number of the Layout to return. + /// @return integer value indicating success/failure of the function. + LIBSBMLNETWORK_EXTERN int c_api_setGeometricShapesId(SBMLDocument* document, const char* id, const char* geometricShapeId, int geometricShapeIndex = 0, int graphicalObjectIndex = 0, int layoutIndex = 0); + /// @brief Sets the geometric shape as the single geometric shape of the RenderGroup of the Style of all SpeciesGlyph objects in this Layout object. /// @param document a pointer to the SBMLDocument object. /// @param shape a string value indicating the shape of the geometric shape to be set. diff --git a/src/libsbmlnetwork_render.cpp b/src/libsbmlnetwork_render.cpp index b19d852..a16dfd8 100755 --- a/src/libsbmlnetwork_render.cpp +++ b/src/libsbmlnetwork_render.cpp @@ -3345,6 +3345,70 @@ int removeGeometricShape(RenderGroup* renderGroup, unsigned int geometricShapeIn return -1; } +const std::string getGeometricShapeId(RenderInformationBase* renderInformationBase, GraphicalObject* graphicalObject, unsigned int geometricShapeIndex) { + return getGeometricShapeId(getStyle(renderInformationBase, graphicalObject), geometricShapeIndex); +} + +const std::string getGeometricShapeId(RenderInformationBase* renderInformationBase, const std::string& attribute, unsigned int geometricShapeIndex ) { + return getGeometricShapeId(getStyle(renderInformationBase, attribute), geometricShapeIndex); +} + +const std::string getGeometricShapeId(Style* style, unsigned int geometricShapeIndex) { + return getGeometricShapeId(getRenderGroup(style), geometricShapeIndex); +} + +const std::string getGeometricShapeId(RenderGroup* renderGroup, unsigned int geometricShapeIndex) { + return getGeometricShapeId(getGeometricShape(renderGroup, geometricShapeIndex)); +} + +const std::string getGeometricShapeId(Transformation2D* shape) { + if (shape) + return shape->getId(); + + return ""; +} + +int setGeometricShapeId(RenderInformationBase* renderInformationBase, GraphicalObject* graphicalObject, const std::string& id) { + return setGeometricShapeId(getStyle(renderInformationBase, graphicalObject), id); +} + +int setGeometricShapeId(RenderInformationBase* renderInformationBase, GraphicalObject* graphicalObject, unsigned int geometricShapeIndex, const std::string& id) { + return setGeometricShapeId(getStyle(renderInformationBase, graphicalObject), geometricShapeIndex, id); +} + +int setGeometricShapeId(RenderInformationBase* renderInformationBase, const std::string& attribute, const std::string& id) { + return setGeometricShapeId(getStyle(renderInformationBase, attribute), id); +} + +int setGeometricShapeId(RenderInformationBase* renderInformationBase, const std::string& attribute, unsigned int geometricShapeIndex, const std::string& id) { + return setGeometricShapeId(getStyle(renderInformationBase, attribute), geometricShapeIndex, id); +} + +int setGeometricShapeId(Style* style, const std::string& id) { + return setGeometricShapeId(getRenderGroup(style), id); +} + +int setGeometricShapeId(Style* style, unsigned int geometricShapeIndex, const std::string& id) { + return setGeometricShapeId(getRenderGroup(style), geometricShapeIndex, id); +} + +int setGeometricShapeId(RenderGroup* renderGroup, const std::string& id) { + return setGeometricShapeId(getGeometricShape(renderGroup), id); +} + +int setGeometricShapeId(RenderGroup* renderGroup, unsigned int geometricShapeIndex, const std::string& id) { + return setGeometricShapeId(getGeometricShape(renderGroup, geometricShapeIndex), id); +} + +int setGeometricShapeId(Transformation2D* shape, const std::string& id) { + if (shape) { + shape->setId(id); + return 0; + } + + return -1; +} + const std::string getGeometricShapeType(RenderInformationBase* renderInformationBase, GraphicalObject* graphicalObject, unsigned int geometricShapeIndex) { return getGeometricShapeType(getStyle(renderInformationBase, graphicalObject), geometricShapeIndex); } diff --git a/src/libsbmlnetwork_render.h b/src/libsbmlnetwork_render.h index 744223e..36ddf00 100755 --- a/src/libsbmlnetwork_render.h +++ b/src/libsbmlnetwork_render.h @@ -2895,6 +2895,34 @@ LIBSBMLNETWORK_EXTERN int removeGeometricShape(RenderGroup* renderGroup, unsigne /// @return integer value indicating success/failure of the function. LIBSBMLNETWORK_EXTERN int addGeometricShape(RenderInformationBase* renderInformationBase, GraphicalObject* graphicalObject, const std::string& shape); +LIBSBMLNETWORK_EXTERN const std::string getGeometricShapeId(RenderInformationBase* renderInformationBase, GraphicalObject* graphicalObject, unsigned int geometricShapeIndex = 0); + +LIBSBMLNETWORK_EXTERN const std::string getGeometricShapeId(RenderInformationBase* renderInformationBase, const std::string& attribute, unsigned int geometricShapeIndex = 0); + +LIBSBMLNETWORK_EXTERN const std::string getGeometricShapeId(Style* style, unsigned int geometricShapeIndex = 0); + +LIBSBMLNETWORK_EXTERN const std::string getGeometricShapeId(RenderGroup* renderGroup, unsigned int geometricShapeIndex = 0); + +LIBSBMLNETWORK_EXTERN const std::string getGeometricShapeId(Transformation2D* shape); + +LIBSBMLNETWORK_EXTERN int setGeometricShapeId(RenderInformationBase* renderInformationBase, GraphicalObject* graphicalObject, const std::string& id); + +LIBSBMLNETWORK_EXTERN int setGeometricShapeId(RenderInformationBase* renderInformationBase, GraphicalObject* graphicalObject, unsigned int geometricShapeIndex, const std::string& id); + +LIBSBMLNETWORK_EXTERN int setGeometricShapeId(RenderInformationBase* renderInformationBase, const std::string& attribute, const std::string& id); + +LIBSBMLNETWORK_EXTERN int setGeometricShapeId(RenderInformationBase* renderInformationBase, const std::string& attribute, unsigned int geometricShapeIndex, const std::string& id); + +LIBSBMLNETWORK_EXTERN int setGeometricShapeId(Style* style, const std::string& id); + +LIBSBMLNETWORK_EXTERN int setGeometricShapeId(Style* style, unsigned int geometricShapeIndex, const std::string& id); + +LIBSBMLNETWORK_EXTERN int setGeometricShapeId(RenderGroup* renderGroup, const std::string& id); + +LIBSBMLNETWORK_EXTERN int setGeometricShapeId(RenderGroup* renderGroup, unsigned int geometricShapeIndex, const std::string& id); + +LIBSBMLNETWORK_EXTERN int setGeometricShapeId(Transformation2D* shape, const std::string& id); + /// @brief Returns the geometric shape as a string based on the RenderInformationBase and GraphicalObject. /// @param renderInformationBase a pointer to the RenderInformationBase object. /// @param graphicalObject a pointer to the GraphicalObject object. diff --git a/src/libsbmlnetwork_sbmldocument_render.cpp b/src/libsbmlnetwork_sbmldocument_render.cpp index f9c1b87..8390e83 100644 --- a/src/libsbmlnetwork_sbmldocument_render.cpp +++ b/src/libsbmlnetwork_sbmldocument_render.cpp @@ -5853,6 +5853,64 @@ int removeGeometricShape(SBMLDocument* document, const std::string& attribute, u return -1; } +const std::string getGeometricShapeId(SBMLDocument* document, GraphicalObject* graphicalObject, unsigned int geometricShapeIndex) { + if (canHaveGeometricShape(graphicalObject)) + return getGeometricShapeId(getStyle(document, graphicalObject), geometricShapeIndex); + + return ""; +} + +const std::string getGeometricShapeId(SBMLDocument* document, const std::string& attribute, unsigned int geometricShapeIndex) { + if (canHaveGeometricShape(getGraphicalObject(document, attribute))) + return getGeometricShapeId(getStyle(document, attribute), geometricShapeIndex); + + return ""; +} + +int setGeometricShapeId(SBMLDocument* document, GraphicalObject* graphicalObject, const std::string& id) { + if (canHaveGeometricShape(graphicalObject)) { + Style* style = getLocalStyle(document, graphicalObject); + if (!style) + style = createLocalStyle(document, graphicalObject); + return setGeometricShapeId(style, id); + } + + return -1; +} + +int setGeometricShapeId(SBMLDocument* document, GraphicalObject* graphicalObject, unsigned int geometricShapeIndex, const std::string& id) { + if (canHaveGeometricShape(graphicalObject)) { + Style* style = getLocalStyle(document, graphicalObject); + if (!style) + style = createLocalStyle(document, graphicalObject); + return setGeometricShapeId(style, geometricShapeIndex, id); + } + + return -1; +} + +int setGeometricShapeId(SBMLDocument* document, const std::string& attribute, const std::string& id) { + if (canHaveGeometricShape(getGraphicalObject(document, attribute))) { + Style* style = getLocalStyle(document, attribute); + if (!style) + style = createLocalStyle(document, attribute); + return setGeometricShapeId(style, id); + } + + return -1; +} + +int setGeometricShapeId(SBMLDocument* document, const std::string& attribute, unsigned int geometricShapeIndex, const std::string& id) { + if (canHaveGeometricShape(getGraphicalObject(document, attribute))) { + Style* style = getLocalStyle(document, attribute); + if (!style) + style = createLocalStyle(document, attribute); + return setGeometricShapeId(style, geometricShapeIndex, id); + } + + return -1; +} + const std::string getGeometricShapeType(SBMLDocument* document, GraphicalObject* graphicalObject, unsigned int geometricShapeIndex) { if (canHaveGeometricShape(graphicalObject)) return getGeometricShapeType(getStyle(document, graphicalObject), geometricShapeIndex); diff --git a/src/libsbmlnetwork_sbmldocument_render.h b/src/libsbmlnetwork_sbmldocument_render.h index 922cadc..dad1cfc 100644 --- a/src/libsbmlnetwork_sbmldocument_render.h +++ b/src/libsbmlnetwork_sbmldocument_render.h @@ -7996,6 +7996,50 @@ LIBSBMLNETWORK_EXTERN int removeGeometricShape(SBMLDocument* document, Graphical /// @return a pointer to the nth Transformation2D of the RenderGroup of the Style for this GraphicalObject, or @c NULL if the object is @c NULL LIBSBMLNETWORK_EXTERN int removeGeometricShape(SBMLDocument* document, const std::string& attribute, unsigned int geometricShapeIndex = 0); +/// @brief Returns the ID of the geometric shape of the Transformation2D at the given index of the RenderGroup of the Style for this GraphicalObject. +/// @param document a pointer to the SBMLDocument object. +/// @param graphicalObject a pointer to the GraphicalObject object. +/// @param geometricShapeIndex an unsigned int representing the index of the Transformation2D to retrieve. +/// @return the ID of the geometric shape of the Transformation2D at the given index of the RenderGroup of the Style for this GraphicalObject, or @c "" if the object is @c NULL +const std::string getGeometricShapeId(SBMLDocument* document, GraphicalObject* graphicalObject, unsigned int geometricShapeIndex); + +/// @brief Returns the value the ID of the geometric shape of the Transformation2D at the given index of the RenderGroup of the Style that matches this attribute (id, role, type) of a GraphicalObject. +/// @param document a pointer to the SBMLDocument object. +/// @param attribute the attribute (id, role, type) of a GraphicalObject. +/// @param geometricShapeIndex an unsigned int representing the index of the Transformation2D to retrieve. +/// @return the ID of the geometric shape of the Transformation2D at the given index of the RenderGroup of the Style for this GraphicalObject, or @c "" if the object is @c NULL +const std::string getGeometricShapeId(SBMLDocument* document, const std::string& attribute, unsigned int geometricShapeIndex); + +/// @brief Sets the ID of the first geometric shape of the RenderGroup of the Style for this GraphicalObject. +/// @param document a pointer to the SBMLDocument object. +/// @param graphicalObject a pointer to the GraphicalObject object. +/// @param id the value to be set as the id of the geometric shape. +/// @return integer value indicating success/failure of the function. +int setGeometricShapeId(SBMLDocument* document, GraphicalObject* graphicalObject, const std::string& id); + +/// @brief Sets the ID of the geometric shape with the given index of the RenderGroup of the Style for this GraphicalObject. +/// @param document a pointer to the SBMLDocument object. +/// @param graphicalObject a pointer to the GraphicalObject object. +/// @param id the value to be set as the id of the geometric shape. +/// @param geometricShapeIndex an unsigned int representing the index of the Transformation2D to retrieve. +/// @return integer value indicating success/failure of the function. +int setGeometricShapeId(SBMLDocument* document, GraphicalObject* graphicalObject, unsigned int geometricShapeIndex, const std::string& id); + +/// @brief Sets the ID of the first geometric shape of the RenderGroup of the Style that matches this attribute (id, role, type) of a GraphicalObject. +/// @param document a pointer to the SBMLDocument object. +/// @param attribute the attribute (id, role, type) of a GraphicalObject. +/// @param id the value to be set as the id of the geometric shape. +/// @return integer value indicating success/failure of the function. +int setGeometricShapeId(SBMLDocument* document, const std::string& attribute, const std::string& id); + +/// @brief Sets the ID of the geometric shape with the given index of the RenderGroup of the Style that matches this attribute (id, role, type) of a GraphicalObject. +/// @param document a pointer to the SBMLDocument object. +/// @param attribute the attribute (id, role, type) of a GraphicalObject. +/// @param id the value to be set as the id of the geometric shape. +/// @param geometricShapeIndex an unsigned int representing the index of the Transformation2D to retrieve. +/// @return integer value indicating success/failure of the function. +int setGeometricShapeId(SBMLDocument* document, const std::string& attribute, unsigned int geometricShapeIndex, const std::string& id); + /// @brief Returns the value the type of the geometric shape of the Transformation2D at the given index of the RenderGroup of the Style for this GraphicalObject. /// @param document a pointer to the SBMLDocument object. /// @param graphicalObject a pointer to the GraphicalObject object. From ecc1865a34da14bcf4b327c449a7c4c82c5f3a46 Mon Sep 17 00:00:00 2001 From: adelhpour Date: Thu, 7 Nov 2024 22:47:26 -0800 Subject: [PATCH 5/8] Reaction glyphs now will have a bounding box representing them if a geometric shape is added to their list of geometric shapes. If all the geometric shapes are removed from this list, then, they are represented by a curve --- src/libsbmlnetwork_layout.cpp | 6 ++-- src/libsbmlnetwork_layout_helpers.cpp | 38 +++++++++++++++++----- src/libsbmlnetwork_layout_helpers.h | 6 ++-- src/libsbmlnetwork_render_helpers.cpp | 9 ++++- src/libsbmlnetwork_render_helpers.h | 2 ++ src/libsbmlnetwork_sbmldocument_render.cpp | 11 +++++-- 6 files changed, 53 insertions(+), 19 deletions(-) diff --git a/src/libsbmlnetwork_layout.cpp b/src/libsbmlnetwork_layout.cpp index ef3b2cb..7c9f322 100755 --- a/src/libsbmlnetwork_layout.cpp +++ b/src/libsbmlnetwork_layout.cpp @@ -1131,10 +1131,8 @@ Curve* getCurve(GraphicalObject* graphicalObject) { } int removeCurve(GraphicalObject* graphicalObject) { - if (isReactionGlyph(graphicalObject)) { - removeReactionGlyphCurve((ReactionGlyph *) graphicalObject); - return 0; - } + if (isReactionGlyph(graphicalObject)) + return removeReactionGlyphCurve((ReactionGlyph*)graphicalObject); return -1; } diff --git a/src/libsbmlnetwork_layout_helpers.cpp b/src/libsbmlnetwork_layout_helpers.cpp index 4bef9d4..3a37ac2 100755 --- a/src/libsbmlnetwork_layout_helpers.cpp +++ b/src/libsbmlnetwork_layout_helpers.cpp @@ -1095,8 +1095,13 @@ void setGraphicalObjectBoundingBox(GraphicalObject* graphicalObject) { } void setReactionGlyphCurve(ReactionGlyph* reactionGlyph) { - if (!reactionGlyph->isSetCurve()) - setCurveCubicBezier(reactionGlyph->getCurve()); + 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) { @@ -1114,6 +1119,20 @@ void setSpeciesReferenceGlyphCurve(SpeciesReferenceGlyph* speciesReferenceGlyph) setCurveCubicBezier(speciesReferenceGlyph->getCurve()); } +int removeReactionGlyphCurve(ReactionGlyph* reactionGlyph) { + double x = getPositionX(reactionGlyph); + double y = getPositionY(reactionGlyph); + double width = getDimensionWidth(reactionGlyph); + double height = getDimensionHeight(reactionGlyph); + while (reactionGlyph->getCurve()->getNumCurveSegments()) + reactionGlyph->getCurve()->getCurveSegment(0)->removeFromParentAndDelete(); + setPositionX(reactionGlyph->getBoundingBox(), x); + setPositionY(reactionGlyph->getBoundingBox(), y); + setDimensionWidth(reactionGlyph->getBoundingBox(), width); + setDimensionHeight(reactionGlyph->getBoundingBox(), height); + return 0; +} + void setTextGlyphBoundingBox(TextGlyph* textGlyph, GraphicalObject* graphicalObject, const double& padding) { textGlyph->getBoundingBox()->setId(textGlyph->getId() + "_bb"); textGlyph->getBoundingBox()->setX(graphicalObject->getBoundingBox()->x() + padding); @@ -1122,11 +1141,6 @@ void setTextGlyphBoundingBox(TextGlyph* textGlyph, GraphicalObject* graphicalObj textGlyph->getBoundingBox()->setHeight(graphicalObject->getBoundingBox()->height()); } -void removeReactionGlyphCurve(ReactionGlyph* reactionGlyph) { - while (reactionGlyph->getCurve()->getNumCurveSegments()) - reactionGlyph->getCurve()->getCurveSegment(0)->removeFromParentAndDelete(); -} - void addCurveSegment(Curve* curve, LineSegment* referenceLineSegment, const double& padding) { if (isCubicBezier(referenceLineSegment)) { CubicBezier* referenceCubicBezier = static_cast(referenceLineSegment); @@ -1149,8 +1163,16 @@ void addCurveSegment(Curve* curve, LineSegment* referenceLineSegment, const doub } } -void setCurveCubicBezier(Curve* curve) { +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) { diff --git a/src/libsbmlnetwork_layout_helpers.h b/src/libsbmlnetwork_layout_helpers.h index e098f1d..c1f50e9 100755 --- a/src/libsbmlnetwork_layout_helpers.h +++ b/src/libsbmlnetwork_layout_helpers.h @@ -224,13 +224,13 @@ void setSpeciesReferenceGlyphCurve(SpeciesReferenceGlyph* speciesReferenceGlyph, void setSpeciesReferenceGlyphCurve(SpeciesReferenceGlyph* speciesReferenceGlyph); -void setTextGlyphBoundingBox(TextGlyph* textGlyph, GraphicalObject* graphicalObject, const double& padding = 0.0); +int removeReactionGlyphCurve(ReactionGlyph* reactionGlyph); -void 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); +void setCurveCubicBezier(Curve* curve, const double& x = 0.0, const double& y = 0.0); Compartment* findCompartmentGlyphCompartment(Model* model, CompartmentGlyph* compartmentGlyph); diff --git a/src/libsbmlnetwork_render_helpers.cpp b/src/libsbmlnetwork_render_helpers.cpp index bd5d0b2..1e225eb 100755 --- a/src/libsbmlnetwork_render_helpers.cpp +++ b/src/libsbmlnetwork_render_helpers.cpp @@ -1181,7 +1181,14 @@ const bool canHaveEndHead(GraphicalObject* graphicalObject) { } const bool canHaveGeometricShape(GraphicalObject* graphicalObject) { - if (isCompartmentGlyph(graphicalObject) || isSpeciesGlyph(graphicalObject) || (isReactionGlyph(graphicalObject) && !getCurve(graphicalObject))) + if (isCompartmentGlyph(graphicalObject) || isSpeciesGlyph(graphicalObject) || (isReactionGlyph(graphicalObject) && !isSetCurve(graphicalObject))) + return true; + + return false; +} + +const bool canPotentiallyHaveGeometricShape(GraphicalObject* graphicalObject) { + if (isCompartmentGlyph(graphicalObject) || isSpeciesGlyph(graphicalObject) || isReactionGlyph(graphicalObject)) return true; return false; diff --git a/src/libsbmlnetwork_render_helpers.h b/src/libsbmlnetwork_render_helpers.h index edd1b5a..56fb1d0 100755 --- a/src/libsbmlnetwork_render_helpers.h +++ b/src/libsbmlnetwork_render_helpers.h @@ -281,6 +281,8 @@ const bool canHaveEndHead(GraphicalObject* graphicalObject); const bool canHaveGeometricShape(GraphicalObject* graphicalObject); +const bool canPotentiallyHaveGeometricShape(GraphicalObject* graphicalObject); + std::string getErrorLog(RenderInformationBase* renderInformation); std::string getErrorLog(ColorDefinition* colorDefinition); diff --git a/src/libsbmlnetwork_sbmldocument_render.cpp b/src/libsbmlnetwork_sbmldocument_render.cpp index 8390e83..23b5438 100644 --- a/src/libsbmlnetwork_sbmldocument_render.cpp +++ b/src/libsbmlnetwork_sbmldocument_render.cpp @@ -5836,7 +5836,12 @@ int removeGeometricShape(SBMLDocument* document, GraphicalObject* graphicalObjec Style* style = getLocalStyle(document, graphicalObject); if (!style) style = createLocalStyle(document, graphicalObject); - return removeGeometricShape(style, geometricShapeIndex); + if (!removeGeometricShape(style, geometricShapeIndex)) { + if (getNumGeometricShapes(style) == 0 && isReactionGlyph(graphicalObject)) + setReactionGlyphCurve((ReactionGlyph*) graphicalObject); + + return 0; + } } return -1; @@ -5926,7 +5931,7 @@ const std::string getGeometricShapeType(SBMLDocument* document, const std::strin } int setGeometricShapeType(SBMLDocument* document, GraphicalObject* graphicalObject, const std::string& shape) { - if (canHaveGeometricShape(graphicalObject)) { + if (canPotentiallyHaveGeometricShape(graphicalObject)) { Style* style = getLocalStyle(document, graphicalObject); if (!style) style = createLocalStyle(document, graphicalObject); @@ -5944,7 +5949,7 @@ int setGeometricShapeType(SBMLDocument* document, GraphicalObject* graphicalObje } int setGeometricShapeType(SBMLDocument* document, const std::string& attribute, const std::string& shape) { - if (canHaveGeometricShape(getGraphicalObject(document, attribute))) { + if (canPotentiallyHaveGeometricShape(getGraphicalObject(document, attribute))) { Style* style = getLocalStyle(document, attribute); if (!style) style = createLocalStyle(document, attribute); From 6371ec69505f687d163014c0099a9e9957a0c799 Mon Sep 17 00:00:00 2001 From: adelhpour Date: Mon, 11 Nov 2024 10:25:58 -0800 Subject: [PATCH 6/8] Modify 'makeSpeciesGlyphsVisible' function to receive a list of species id, reaction id, and reaction glyph index as its input --- .../python/ctypes/libsbmlnetwork.py.cmake | 35 +++++++++++++------ src/c_api/libsbmlnetwork_c_api.cpp | 17 ++++++--- src/c_api/libsbmlnetwork_c_api.h | 4 +-- src/libsbmlnetwork_layout_helpers.cpp | 35 +++---------------- src/libsbmlnetwork_layout_helpers.h | 6 +--- src/libsbmlnetwork_sbmldocument_layout.cpp | 8 ++--- src/libsbmlnetwork_sbmldocument_layout.h | 8 ++--- 7 files changed, 52 insertions(+), 61 deletions(-) diff --git a/src/bindings/python/ctypes/libsbmlnetwork.py.cmake b/src/bindings/python/ctypes/libsbmlnetwork.py.cmake index 8209a25..a1fb5bb 100644 --- a/src/bindings/python/ctypes/libsbmlnetwork.py.cmake +++ b/src/bindings/python/ctypes/libsbmlnetwork.py.cmake @@ -490,13 +490,17 @@ class LibSBMLNetwork: """ return lib.c_api_makeSpeciesGlyphVisible(self.sbml_object, str(species_id).encode(), str(reaction_id).encode(), visible, reaction_glyph_index, layout_index) - def makeSpeciesGlyphsVisible(self, species_ids=None, visible=True, layout_index=0): + def makeSpeciesGlyphsVisible(self, species=None, visible=True, layout_index=0): """ Makes the SpeciesGlyphs of Species with the given species_ids in the Layout object with the given index in the given SBMLDocument visible or invisible :Parameters: - - species_ids (list of strings): a list of strings that determines the ids of the Species + - species = (list of lists or list of strings, optional): a list (default: None) that determines the list of Species. The list contains: + - a list of lists where each list includes: + - 'id' (str): the ID of the Species + - 'reaction_id' (str): the ID of the Reaction + - 'reaction_glyph_index' (int, optional): the index (default: 0) of the ReactionGlyph in the given SBMLDocument - visible = (boolean, optional): a boolean (default: True) that determines whether to make the SpeciesGlyphs visible or invisible - layout_index (int, optional): an integer (default: 0) that determines the index of the Layout object in the given SBMLDocument @@ -504,15 +508,26 @@ class LibSBMLNetwork: true on success and false if the SpeciesGlyphs could not be hidden """ - species_ids_ptr = None - species_ids_len = 0 - if species_ids is not None: - species_ids_len = len(species_ids) - species_ids_ptr = (ctypes.c_char_p * len(species_ids))() - for i in range(len(species_ids)): - species_ids_ptr[i] = ctypes.c_char_p(species_ids[i].encode()) + species_ptr = None + if species is not None: + species_ptr = (ctypes.POINTER(ctypes.c_char_p) * len(species))() + for i in range(len(species)): + a_species_ptr = (ctypes.c_char_p * 3)() + if isinstance(species[i], list): + if len(species[i]) == 3: + print(species[i]) + a_species_ptr[0] = ctypes.c_char_p(str(species[i][0]).encode()) + a_species_ptr[1] = ctypes.c_char_p(str(species[i][1]).encode()) + a_species_ptr[2] = ctypes.c_char_p(str(species[i][2]).encode()) + elif len(species[i]) == 2: + a_species_ptr[0] = ctypes.c_char_p(str(species[i][0]).encode()) + a_species_ptr[1] = ctypes.c_char_p(str(species[i][1]).encode()) + a_species_ptr[2] = ctypes.c_char_p(str(0).encode()) + else: + raise Exception("The species parameter should be a list of lists with species id, reaction id, and reaction glyph index or a list of lists with species id and reaction id.") + species_ptr[i] = a_species_ptr - return lib.c_api_makeSpeciesGlyphsVisible(self.sbml_object, species_ids_ptr, species_ids_len, visible, layout_index) + return lib.c_api_makeSpeciesGlyphsVisible(self.sbml_object, species_ptr, len(species_ptr), visible, layout_index) def getCanvasWidth(self, layout_index=0): """ diff --git a/src/c_api/libsbmlnetwork_c_api.cpp b/src/c_api/libsbmlnetwork_c_api.cpp index 772a38f..8632688 100644 --- a/src/c_api/libsbmlnetwork_c_api.cpp +++ b/src/c_api/libsbmlnetwork_c_api.cpp @@ -138,12 +138,19 @@ namespace LIBSBMLNETWORK_CPP_NAMESPACE { return makeSpeciesGlyphVisible(document, layoutIndex, speciesId, reactionId, reactionGlyphIndex, visible); } - int c_api_makeSpeciesGlyphsVisible(SBMLDocument* document, const char** speciesIds, const int speciesIdsSize, const bool visible, int layoutIndex) { - std::set speciesIdsSet = std::set(); - for (int i = 0; i < speciesIdsSize; i++) - speciesIdsSet.insert(speciesIds[i]); + int c_api_makeSpeciesGlyphsVisible(SBMLDocument* document, const char ***species, const int speciesSize, const bool visible, int layoutIndex) { + std::set > speciesSet = std::set >(); + if (species) { + for (int i = 0; i < speciesSize; i++) { + const char **aSpecies = species[i]; + const char *speciesId = aSpecies[0]; + const char *reactionId = aSpecies[1]; + int reactionGlyphIndex = atoi(aSpecies[2]); + speciesSet.insert(std::make_tuple(speciesId, reactionId, reactionGlyphIndex)); + } + } - return makeSpeciesGlyphsVisible(document, layoutIndex, speciesIdsSet, visible); + return makeSpeciesGlyphsVisible(document, layoutIndex, speciesSet, visible); } double c_api_getCanvasWidth(SBMLDocument* document, int layoutIndex) { diff --git a/src/c_api/libsbmlnetwork_c_api.h b/src/c_api/libsbmlnetwork_c_api.h index 2313d2a..55d1da0 100644 --- a/src/c_api/libsbmlnetwork_c_api.h +++ b/src/c_api/libsbmlnetwork_c_api.h @@ -163,12 +163,12 @@ namespace LIBSBMLNETWORK_CPP_NAMESPACE { /// @brief Hide the SpeciesGlyphs with the given species Ids in the Layout object with the given index in the ListOfLayouts of the SBML document. /// @param document a pointer to the SBMLDocument object. - /// @param speciesIds an array of strings containing the ids of the species to hide the SpeciesGlyphs for. + /// @param species an array of strings containing the ids of the species, ids of the reactions, and the indices of the reaction glyphs that the species are participants of. /// @param speciesIdsSize the size of speciesIds /// @param visible a boolean value to determine whether make SpeciesGlyph visible or invisible. /// @param layoutIndex the index number of the Layout to return. /// @return integer value indicating success/failure of the function. - LIBSBMLNETWORK_EXTERN int c_api_makeSpeciesGlyphsVisible(SBMLDocument* document, const char** speciesIds, const int speciesIdsSize, bool visible = true, int layoutIndex = 0); + LIBSBMLNETWORK_EXTERN int c_api_makeSpeciesGlyphsVisible(SBMLDocument* document, const char ***species, const int speciesSize, const bool visible, int layoutIndex); /// @brief Returns the value of the "width" attribute of the Dimensions object of the Layout object /// with the given index in the ListOfLayouts of the SBML document. diff --git a/src/libsbmlnetwork_layout_helpers.cpp b/src/libsbmlnetwork_layout_helpers.cpp index 3a37ac2..3f97f3c 100755 --- a/src/libsbmlnetwork_layout_helpers.cpp +++ b/src/libsbmlnetwork_layout_helpers.cpp @@ -655,17 +655,12 @@ int setSpeciesGlyphIndexInReactionGlyph(Layout* layout, const std::string specie return -1; } -int makeSpeciesGlyphsVisible(Model* model, Layout* layout, std::set speciesIds, bool visible) { - if (!speciesIds.size()) { - for (unsigned int i = 0; i < model->getNumSpecies(); i++) - speciesIds.insert(model->getSpecies(i)->getId()); +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; } - if (!visible) - hideSpeciesGlyphs(layout, speciesIds); - else - unHideSpeciesGlyphs(layout, speciesIds); - return 0; } @@ -676,28 +671,6 @@ int makeSpeciesGlyphVisible(ReactionGlyph* reactionGlyph, const std::string spec return unHideSpeciesGlyph(reactionGlyph, speciesId); } -int hideSpeciesGlyphs(Layout* layout, std::set speciesIds) { - for (std::set::const_iterator speciesIdsIt = speciesIds.cbegin(); speciesIdsIt != speciesIds.cend(); speciesIdsIt++) { - if (hideSpeciesGlyph(layout, *speciesIdsIt)) - return -1; - } - - return 0; -} - -int unHideSpeciesGlyphs(Layout* layout, std::set speciesIds) { - for (std::set::const_iterator speciesIdsIt = speciesIds.cbegin(); speciesIdsIt != speciesIds.cend(); speciesIdsIt++) { - if (unHideSpeciesGlyph(layout, *speciesIdsIt)) - return -1; - for (unsigned int i = 0; i < layout->getNumReactionGlyphs(); i++) { - ReactionGlyph* reactionGlyph = layout->getReactionGlyph(i); - makeSpeciesGlyphVisible(reactionGlyph, *speciesIdsIt, true); - } - } - - return 0; -} - int hideSpeciesGlyph(SBase* sBase, const std::string speciesId) { if (sBase) { std::string hiddenSpeciesIds = getUserData(sBase, "hidden_species_ids"); diff --git a/src/libsbmlnetwork_layout_helpers.h b/src/libsbmlnetwork_layout_helpers.h index c1f50e9..45e20a4 100755 --- a/src/libsbmlnetwork_layout_helpers.h +++ b/src/libsbmlnetwork_layout_helpers.h @@ -136,14 +136,10 @@ SpeciesGlyph* getSpeciesGlyph(Layout* layout, const std::string& speciesId, cons int setSpeciesGlyphIndexInReactionGlyph(Layout* layout, const std::string speciesId, ReactionGlyph* reactionGlyph, const unsigned int index); -int makeSpeciesGlyphsVisible(Model* model, Layout* layout, std::set speciesIds, bool visible = true); +int makeSpeciesGlyphsVisible(Model* model, Layout* layout, std::set > species, bool visible = true); int makeSpeciesGlyphVisible(ReactionGlyph* reactionGlyph, const std::string speciesId, bool visible = true); -int hideSpeciesGlyphs(Layout* layout, std::set speciesIds); - -int unHideSpeciesGlyphs(Layout* layout, std::set speciesIds); - int hideSpeciesGlyph(SBase* sBase, const std::string speciesId); int unHideSpeciesGlyph(SBase* sBase, const std::string speciesId); diff --git a/src/libsbmlnetwork_sbmldocument_layout.cpp b/src/libsbmlnetwork_sbmldocument_layout.cpp index fb4d093..1c861ee 100644 --- a/src/libsbmlnetwork_sbmldocument_layout.cpp +++ b/src/libsbmlnetwork_sbmldocument_layout.cpp @@ -190,9 +190,9 @@ int makeSpeciesGlyphVisible(SBMLDocument* document, unsigned int layoutIndex, co return -1; } -int makeSpeciesGlyphsVisible(SBMLDocument* document, const std::set& speciesIds, bool visible) { +int makeSpeciesGlyphsVisible(SBMLDocument* document, const std::set >& species, bool visible) { if (document && document->isSetModel()) { - if (!makeSpeciesGlyphsVisible(document->getModel(), getLayout(document), speciesIds, visible)) + if (!makeSpeciesGlyphsVisible(document->getModel(), getLayout(document), species, visible)) return setDefaultLayoutLocations(document, getLayout(document)); } @@ -200,9 +200,9 @@ int makeSpeciesGlyphsVisible(SBMLDocument* document, const std::set return -1; } -int makeSpeciesGlyphsVisible(SBMLDocument* document, unsigned int layoutIndex, const std::set& speciesIds, bool visible) { +int makeSpeciesGlyphsVisible(SBMLDocument* document, unsigned int layoutIndex, const std::set >& species, bool visible) { if (document && document->isSetModel()) { - if (!makeSpeciesGlyphsVisible(document->getModel(), getLayout(document, layoutIndex), speciesIds, visible)) + if (!makeSpeciesGlyphsVisible(document->getModel(), getLayout(document, layoutIndex), species, visible)) return setDefaultLayoutLocations(document, getLayout(document, layoutIndex)); } diff --git a/src/libsbmlnetwork_sbmldocument_layout.h b/src/libsbmlnetwork_sbmldocument_layout.h index 8b6066b..69f9904 100644 --- a/src/libsbmlnetwork_sbmldocument_layout.h +++ b/src/libsbmlnetwork_sbmldocument_layout.h @@ -167,18 +167,18 @@ LIBSBMLNETWORK_EXTERN int makeSpeciesGlyphVisible(SBMLDocument* document, unsign /// @brief Makes the Species Glyph with the given species Id which is a participant of the reaction with the given Id and index in the first Layout object in the ListOfLayouts of the SBML document visible or invisible. /// @param document a pointer to the SBMLDocument object. -/// @param speciesIds a set of the ids of the Species to hide/show. +/// @param species a set of tuples of the ids of the Species, the id of the Reaction, and the index of the ReactionGlyph object to hide/show the SpeciesGlyph for. /// @param visible a boolean value to determine whether to make the SpeciesGlyph visible or invisible. /// @return integer value indicating success/failure of the function. -LIBSBMLNETWORK_EXTERN int makeSpeciesGlyphsVisible(SBMLDocument* document, const std::set& speciesIds, bool visible); +LIBSBMLNETWORK_EXTERN int makeSpeciesGlyphsVisible(SBMLDocument* document, const std::set >& species, bool visible); /// @brief Makes the Species Glyph with the given species Id which is a participant of the reaction with the given Id and index in the Layout object with the given index in the ListOfLayouts of the SBML document visible or invisible. /// @param document a pointer to the SBMLDocument object. /// @param layoutIndex the index number of the Layout to return. -/// @param speciesIds a set of the ids of the Species to hide/show. +/// @param species a set of tuples of the ids of the Species, the id of the Reaction, and the index of the ReactionGlyph object to hide/show the SpeciesGlyph for. /// @param visible a boolean value to determine whether to make the SpeciesGlyph visible or invisible. /// @return integer value indicating success/failure of the function. -LIBSBMLNETWORK_EXTERN int makeSpeciesGlyphsVisible(SBMLDocument* document, unsigned int layoutIndex, const std::set& speciesIds, bool visible); +LIBSBMLNETWORK_EXTERN int makeSpeciesGlyphsVisible(SBMLDocument* document, unsigned int layoutIndex, const std::set >& species, bool visible); /// @brief Returns the Dimensions object of the Layout object with the given index in the ListOfLayouts of the SBML document. /// @param document a pointer to the SBMLDocument object. From a484fd9f82c73983c19d872bb54f0924ba541802 Mon Sep 17 00:00:00 2001 From: adelhpour Date: Mon, 11 Nov 2024 22:14:38 -0800 Subject: [PATCH 7/8] fix the issue with passing a reaction with bounding box to autolayout algorithm --- src/autolayout/libsbmlnetwork_autolayout.cpp | 27 +++- .../libsbmlnetwork_autolayout_node.cpp | 120 +++++++++++------- .../libsbmlnetwork_autolayout_node.h | 6 +- 3 files changed, 94 insertions(+), 59 deletions(-) diff --git a/src/autolayout/libsbmlnetwork_autolayout.cpp b/src/autolayout/libsbmlnetwork_autolayout.cpp index c08b063..a2fbbb4 100755 --- a/src/autolayout/libsbmlnetwork_autolayout.cpp +++ b/src/autolayout/libsbmlnetwork_autolayout.cpp @@ -154,8 +154,12 @@ randomizeSpeciesGlyphsLocations(Model *model, Layout *layout, const double &canv } void randomizeReactionGlyphsLocations(Model *model, Layout *layout, const double &canvasWidth, const double &canvasHeight) { - for (int i = 0; i < layout->getNumReactionGlyphs(); i++) - randomizeCurveCenterPoint(layout->getReactionGlyph(i)->getCurve(), canvasWidth, canvasHeight); + for (int i = 0; i < layout->getNumReactionGlyphs(); i++) { + if (layout->getReactionGlyph(i)->isSetCurve()) + randomizeCurveCenterPoint(layout->getReactionGlyph(i)->getCurve(), canvasWidth, canvasHeight); + else + randomizeBoundingBoxesPosition(layout->getReactionGlyph(i)->getBoundingBox(), canvasWidth, canvasHeight); + } } void @@ -218,9 +222,14 @@ void updateCompartmentsExtentsUsingTheirElementsExtents(Model *model, Layout *la for (int i = 0; i < layout->getNumReactionGlyphs(); i++) { CompartmentGlyph *compartmentGlyph = getCompartmentGlyphOfReactionGlyph(model, layout, layout->getReactionGlyph(i)); - if (compartmentGlyph) - updateCompartmentExtentsUsingItsElementsExtents(compartmentGlyph->getBoundingBox(), - layout->getReactionGlyph(i)->getCurve()); + if (compartmentGlyph) { + if (layout->getReactionGlyph(i)->isSetCurve()) + updateCompartmentExtentsUsingItsElementsExtents(compartmentGlyph->getBoundingBox(), + layout->getReactionGlyph(i)->getCurve()); + else + updateCompartmentExtentsUsingItsElementsExtents(compartmentGlyph->getBoundingBox(), + layout->getReactionGlyph(i)->getBoundingBox()); + } } } @@ -380,8 +389,12 @@ void extractExtents(Layout *layout, double &maxX, double &maxY) { 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); - for (int i = 0; i < layout->getNumReactionGlyphs(); i++) - extractExtents(layout->getReactionGlyph(i)->getCurve(), 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); + else + extractExtents(layout->getReactionGlyph(i)->getBoundingBox(), minX, minY, maxX, maxY); + } } void extractExtents(BoundingBox *boundingBox, double &minX, double &minY, double &maxX, double &maxY) { diff --git a/src/autolayout/libsbmlnetwork_autolayout_node.cpp b/src/autolayout/libsbmlnetwork_autolayout_node.cpp index a91d992..b53bdf9 100644 --- a/src/autolayout/libsbmlnetwork_autolayout_node.cpp +++ b/src/autolayout/libsbmlnetwork_autolayout_node.cpp @@ -169,51 +169,65 @@ GraphicalObject* AutoLayoutCentroidNode::getGraphicalObject() { void AutoLayoutCentroidNode::updateDimensions() { std::string fixedWidth = LIBSBMLNETWORK_CPP_NAMESPACE::getUserData(getGraphicalObject(), "width"); if (fixedWidth.empty()) - setBoundingBoxWidth(std::max(calculateWidth(), getWidth())); - else { + setWidth(std::max(calculateWidth(), getWidth())); + else setWidth(std::stod(fixedWidth)); - setBoundingBoxWidth(std::stod(fixedWidth)); - } std::string fixedHeight = LIBSBMLNETWORK_CPP_NAMESPACE::getUserData(getGraphicalObject(), "height"); if (fixedHeight.empty()) - setBoundingBoxHeight(std::max(calculateHeight(), getHeight())); - else { + setHeight(std::max(calculateHeight(), getHeight())); + else setHeight(std::stod(fixedHeight)); - setBoundingBoxHeight(std::stod(fixedHeight)); - } } const double AutoLayoutCentroidNode::getX() { - const LineSegment* ls = getCurve()->getCurveSegment(0); - return 0.5 * (ls->getStart()->x() + ls->getEnd()->x()); + if (isSetCurve()) { + const LineSegment* ls = getCurve()->getCurveSegment(0); + return 0.5 * (ls->getStart()->x() + ls->getEnd()->x()); + } + + return _graphicalObject->getBoundingBox()->x(); } void AutoLayoutCentroidNode::setX(const double& x) { - Curve* curve = getCurve(); - curve->getCurveSegment(0)->getStart()->setX(x); - ((CubicBezier*)(curve->getCurveSegment(0)))->getBasePoint1()->setX(x); - curve->getCurveSegment(0)->getEnd()->setX(x); - ((CubicBezier*)(curve->getCurveSegment(0)))->getBasePoint2()->setX(x); - _graphicalObject->getBoundingBox()->setX(x); + if (isSetCurve()) { + Curve* curve = getCurve(); + curve->getCurveSegment(0)->getStart()->setX(x); + ((CubicBezier*)(curve->getCurveSegment(0)))->getBasePoint1()->setX(x); + curve->getCurveSegment(0)->getEnd()->setX(x); + ((CubicBezier*)(curve->getCurveSegment(0)))->getBasePoint2()->setX(x); + } + else + _graphicalObject->getBoundingBox()->setX(x); } const double AutoLayoutCentroidNode::getY() { - const LineSegment* ls = getCurve()->getCurveSegment(0); - return 0.5 * (ls->getStart()->y() + ls->getEnd()->y()); + if (isSetCurve()) { + const LineSegment* ls = getCurve()->getCurveSegment(0); + return 0.5 * (ls->getStart()->y() + ls->getEnd()->y()); + } + + return _graphicalObject->getBoundingBox()->y(); } void AutoLayoutCentroidNode::setY(const double& y) { - Curve* curve = getCurve(); - curve->getCurveSegment(0)->getStart()->setY(y); - ((CubicBezier*)(curve->getCurveSegment(0)))->getBasePoint1()->setY(y); - curve->getCurveSegment(0)->getEnd()->setY(y); - ((CubicBezier*)(curve->getCurveSegment(0)))->getBasePoint2()->setY(y); - _graphicalObject->getBoundingBox()->setY(y); + if (isSetCurve()) { + Curve* curve = getCurve(); + curve->getCurveSegment(0)->getStart()->setY(y); + ((CubicBezier*)(curve->getCurveSegment(0)))->getBasePoint1()->setY(y); + curve->getCurveSegment(0)->getEnd()->setY(y); + ((CubicBezier*)(curve->getCurveSegment(0)))->getBasePoint2()->setY(y); + } + else + _graphicalObject->getBoundingBox()->setY(y); } const double AutoLayoutCentroidNode::getWidth() { - const LineSegment* ls = getCurve()->getCurveSegment(0); - return ls->getEnd()->x() - ls->getStart()->x(); + if (isSetCurve()) { + const LineSegment* ls = getCurve()->getCurveSegment(0); + return ls->getEnd()->x() - ls->getStart()->x(); + } + + return _graphicalObject->getBoundingBox()->width(); } const double AutoLayoutCentroidNode::getDefaultWidth() { @@ -222,21 +236,25 @@ const double AutoLayoutCentroidNode::getDefaultWidth() { void AutoLayoutCentroidNode::setWidth(const double& width) { if (std::abs(width - getWidth())) { - Curve* curve = getCurve(); - curve->getCurveSegment(0)->getStart()->setX(curve->getCurveSegment(0)->getStart()->x() - 0.5 * std::abs(width - getWidth())); - ((CubicBezier*)(curve->getCurveSegment(0)))->getBasePoint1()->setX(((CubicBezier*)(curve->getCurveSegment(0)))->getBasePoint1()->x() - 0.5 * std::abs(width - getWidth())); - curve->getCurveSegment(0)->getEnd()->setX(curve->getCurveSegment(0)->getEnd()->x() + 0.5 * std::abs(width - getWidth())); - ((CubicBezier*)(curve->getCurveSegment(0)))->getBasePoint2()->setX(((CubicBezier*)(curve->getCurveSegment(0)))->getBasePoint2()->x() - 0.5 * std::abs(width - getWidth())); + if (isSetCurve()) { + Curve* curve = getCurve(); + curve->getCurveSegment(0)->getStart()->setX(curve->getCurveSegment(0)->getStart()->x() - 0.5 * std::abs(width - getWidth())); + ((CubicBezier*)(curve->getCurveSegment(0)))->getBasePoint1()->setX(((CubicBezier*)(curve->getCurveSegment(0)))->getBasePoint1()->x() - 0.5 * std::abs(width - getWidth())); + curve->getCurveSegment(0)->getEnd()->setX(curve->getCurveSegment(0)->getEnd()->x() + 0.5 * std::abs(width - getWidth())); + ((CubicBezier*)(curve->getCurveSegment(0)))->getBasePoint2()->setX(((CubicBezier*)(curve->getCurveSegment(0)))->getBasePoint2()->x() - 0.5 * std::abs(width - getWidth())); + } + else + _graphicalObject->getBoundingBox()->setWidth(width); } } -void AutoLayoutCentroidNode::setBoundingBoxWidth(const double& width) { - _graphicalObject->getBoundingBox()->setWidth(width); -} - const double AutoLayoutCentroidNode::getHeight() { - const LineSegment* ls = getCurve()->getCurveSegment(0); - return ls->getEnd()->y() - ls->getStart()->y(); + if (isSetCurve()) { + const LineSegment* ls = getCurve()->getCurveSegment(0); + return ls->getEnd()->y() - ls->getStart()->y(); + } + + return _graphicalObject->getBoundingBox()->height(); } const double AutoLayoutCentroidNode::getDefaultHeight() { @@ -245,18 +263,18 @@ const double AutoLayoutCentroidNode::getDefaultHeight() { void AutoLayoutCentroidNode::setHeight(const double& height) { if (std::abs(height - getHeight())) { - Curve* curve = getCurve(); - curve->getCurveSegment(0)->getStart()->setY(curve->getCurveSegment(0)->getStart()->y() - 0.5 * std::abs(height - getHeight())); - ((CubicBezier*)(curve->getCurveSegment(0)))->getBasePoint1()->setY(((CubicBezier*)(curve->getCurveSegment(0)))->getBasePoint1()->y() - 0.5 * std::abs(height - getHeight())); - curve->getCurveSegment(0)->getEnd()->setY(curve->getCurveSegment(0)->getEnd()->y() + 0.5 * std::abs(height - getHeight())); - ((CubicBezier*)(curve->getCurveSegment(0)))->getBasePoint2()->setY(((CubicBezier*)(curve->getCurveSegment(0)))->getBasePoint2()->y() - 0.5 * std::abs(height - getHeight())); + if (isSetCurve()) { + Curve* curve = getCurve(); + curve->getCurveSegment(0)->getStart()->setY(curve->getCurveSegment(0)->getStart()->y() - 0.5 * std::abs(height - getHeight())); + ((CubicBezier*)(curve->getCurveSegment(0)))->getBasePoint1()->setY(((CubicBezier*)(curve->getCurveSegment(0)))->getBasePoint1()->y() - 0.5 * std::abs(height - getHeight())); + curve->getCurveSegment(0)->getEnd()->setY(curve->getCurveSegment(0)->getEnd()->y() + 0.5 * std::abs(height - getHeight())); + ((CubicBezier*)(curve->getCurveSegment(0)))->getBasePoint2()->setY(((CubicBezier*)(curve->getCurveSegment(0)))->getBasePoint2()->y() - 0.5 * std::abs(height - getHeight())); + } + else + _graphicalObject->getBoundingBox()->setHeight(height); } } -void AutoLayoutCentroidNode::setBoundingBoxHeight(const double& height) { - _graphicalObject->getBoundingBox()->setHeight(height); -} - const double AutoLayoutCentroidNode::calculateWidth() { ReactionGlyph* reactionGlyph = (ReactionGlyph*)_graphicalObject; std::string displayedText = reactionGlyph->getReactionId(); @@ -271,7 +289,13 @@ const double AutoLayoutCentroidNode::calculateHeight() { return std::max(LIBSBMLNETWORK_CPP_NAMESPACE::getReactionDefaultHeight(), getHeight()); } +const bool AutoLayoutCentroidNode::isSetCurve() { + return ((ReactionGlyph*)_graphicalObject)->isSetCurve(); +} + Curve* AutoLayoutCentroidNode::getCurve() { - ReactionGlyph* reactionGlyph = (ReactionGlyph*)_graphicalObject; - return reactionGlyph->getCurve(); + if (isSetCurve()) + return ((ReactionGlyph*)_graphicalObject)->getCurve(); + + return NULL; } diff --git a/src/autolayout/libsbmlnetwork_autolayout_node.h b/src/autolayout/libsbmlnetwork_autolayout_node.h index 5ca816d..9a9d1f5 100644 --- a/src/autolayout/libsbmlnetwork_autolayout_node.h +++ b/src/autolayout/libsbmlnetwork_autolayout_node.h @@ -134,20 +134,18 @@ class AutoLayoutCentroidNode : public AutoLayoutNodeBase { void setWidth(const double& width) override; - void setBoundingBoxWidth(const double& width); - const double getHeight() override; const double getDefaultHeight() override; void setHeight(const double& height) override; - void setBoundingBoxHeight(const double& height); - const double calculateWidth() override; const double calculateHeight() override; + const bool isSetCurve(); + Curve* getCurve(); }; From 3766dce83479c23a19ca73cf490893e12518389f Mon Sep 17 00:00:00 2001 From: adelhpour Date: Mon, 11 Nov 2024 22:15:06 -0800 Subject: [PATCH 8/8] version is updated to 0.4.1 --- VERSION.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION.txt b/VERSION.txt index 60a2d3e..44bb5d1 100755 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -0.4.0 \ No newline at end of file +0.4.1 \ No newline at end of file