Skip to content

Commit

Permalink
Merge pull request #18 from sys-bio/add-features-fix-bugs
Browse files Browse the repository at this point in the history
Fix minor bugs
  • Loading branch information
adelhpour authored Dec 3, 2024
2 parents 1dd539e + be25f2b commit 4be22c2
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/c_api/libsbmlnetwork_c_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ namespace LIBSBMLNETWORK_CPP_NAMESPACE {
/// @param graphicalObjectIndex the index number of the GraphicalObject to return.
/// @param layoutIndex the index number of the Layout to return.
/// @return the id of the compartment associated with the given GraphicalObject, or @c "" if the object does not exists.
LIBSBMLNETWORK_EXTERN const char* c_api_getCGraphicalObjectCompartmentId(SBMLDocument* document, const char* id, int graphicalObjectIndex = 0, int layoutIndex = 0);
LIBSBMLNETWORK_EXTERN const char* c_api_getGraphicalObjectCompartmentId(SBMLDocument* document, const char* id, int graphicalObjectIndex = 0, int layoutIndex = 0);

/// @brief Returns the number of Species objects in the given SBML document.
/// @param document a pointer to the SBMLDocument object.
Expand Down
17 changes: 13 additions & 4 deletions src/features/hide_elements/libsbmlnetwork_hide_elements.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "libsbmlnetwork_hide_elements.h"
#include "../../libsbmlnetwork_sbmldocument_layout.h"
#include "../../libsbmlnetwork_layout.h"
#include "../../libsbmlnetwork_layout_helpers.h"
#include "../../libsbmlnetwork_sbmldocument_render.h"
#include "../../libsbmlnetwork_render.h"
#include "../../libsbmlnetwork_render_helpers.h"
Expand Down Expand Up @@ -297,15 +298,19 @@ int hide_elements_makeSpeciesGlyphVisible(SBMLDocument* document, SpeciesGlyph*
Style* style = getLocalStyle(document, speciesGlyph);
if (!style)
style = createLocalStyle(document, speciesGlyph);
Layout* layout = getLayout(document);
hide_elements_make2DGraphicalObjectVisible(document, style);
std::vector<TextGlyph*> textGlyphs = getTextGlyphs(getLayout(document), speciesGlyph);
std::vector<TextGlyph*> textGlyphs = getTextGlyphs(layout, speciesGlyph);
for (std::vector<TextGlyph*>::const_iterator textGlyphIt = textGlyphs.cbegin(); textGlyphIt != textGlyphs.cend(); textGlyphIt++)
hide_elements_makeTextGlyphVisible(document, *textGlyphIt, speciesGlyph);
if (applyToConnectedElements) {
std::vector<SpeciesReferenceGlyph*> speciesReferenceGlyphs = set_layout_features_getConnectedSpeciesGlyphReferences(getLayout(document), speciesGlyph);
std::vector<SpeciesReferenceGlyph*> speciesReferenceGlyphs = set_layout_features_getConnectedSpeciesGlyphReferences(layout, speciesGlyph);
for (std::vector<SpeciesReferenceGlyph*>::const_iterator speciesReferenceGlyphIt = speciesReferenceGlyphs.cbegin(); speciesReferenceGlyphIt != speciesReferenceGlyphs.cend(); speciesReferenceGlyphIt++) {
if (hide_elements_makeSpeciesReferenceGlyphVisible(document, *speciesReferenceGlyphIt))
return -1;
ReactionGlyph* reactionGlyph = findSpeciesReferenceReactionGlyph(layout, *speciesReferenceGlyphIt);
if (isUniUniReaction(document->getModel(), reactionGlyph))
hide_elements_makeReactionGlyphVisible(document, reactionGlyph, true);
}
}

Expand All @@ -320,15 +325,19 @@ int hide_elements_makeSpeciesGlyphInvisible(SBMLDocument* document, SpeciesGlyph
Style* style = getLocalStyle(document, speciesGlyph);
if (!style)
style = createLocalStyle(document, speciesGlyph);
Layout* layout = getLayout(document);
hide_elements_make2DGraphicalObjectInvisible(document, style);
std::vector<TextGlyph*> textGlyphs = getTextGlyphs(getLayout(document), speciesGlyph);
std::vector<TextGlyph*> textGlyphs = getTextGlyphs(layout, speciesGlyph);
for (std::vector<TextGlyph*>::const_iterator textGlyphIt = textGlyphs.cbegin(); textGlyphIt != textGlyphs.cend(); textGlyphIt++)
hide_elements_makeTextGlyphInvisible(document, *textGlyphIt, speciesGlyph);
if (applyToConnectedElements) {
std::vector<SpeciesReferenceGlyph*> speciesReferenceGlyphs = set_layout_features_getConnectedSpeciesGlyphReferences(getLayout(document), speciesGlyph);
std::vector<SpeciesReferenceGlyph*> speciesReferenceGlyphs = set_layout_features_getConnectedSpeciesGlyphReferences(layout, speciesGlyph);
for (std::vector<SpeciesReferenceGlyph*>::const_iterator speciesReferenceGlyphIt = speciesReferenceGlyphs.cbegin(); speciesReferenceGlyphIt != speciesReferenceGlyphs.cend(); speciesReferenceGlyphIt++) {
if (hide_elements_makeSpeciesReferenceGlyphInvisible(document, *speciesReferenceGlyphIt))
return -1;
ReactionGlyph* reactionGlyph = findSpeciesReferenceReactionGlyph(layout, *speciesReferenceGlyphIt);
if (isUniUniReaction(document->getModel(), reactionGlyph))
hide_elements_makeReactionGlyphInvisible(document, reactionGlyph, true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ std::vector<SpeciesReferenceGlyph*> set_layout_features_getConnectedSpeciesGlyph

const std::string set_layout_features_getCompartmentGlyphId(Layout* layout, const std::string compartmentId) {
std::string compartmentGlyphId = "";
int compartmentGlyphIndex = 1;
int compartmentGlyphIndex = 0;
std::vector<CompartmentGlyph*> compartmentGlyphs = getAssociatedCompartmentGlyphsWithCompartmentId(layout, compartmentId);
while (true) {
compartmentGlyphId = compartmentId + "_Glyph_" + std::to_string(compartmentGlyphIndex++);
Expand All @@ -361,7 +361,7 @@ const std::string set_layout_features_getCompartmentGlyphId(Layout* layout, cons

const std::string set_layout_features_getSpeciesGlyphId(Layout* layout, const std::string speciesId) {
std::string speciesGlyphId = "";
int speciesGlyphIndex = 1;
int speciesGlyphIndex = 0;
std::vector<SpeciesGlyph*> speciesGlyphs = getAssociatedSpeciesGlyphsWithSpeciesId(layout, speciesId);
while (true) {
speciesGlyphId = speciesId + "_Glyph_" + std::to_string(speciesGlyphIndex++);
Expand All @@ -381,7 +381,7 @@ const std::string set_layout_features_getSpeciesGlyphId(Layout* layout, const st

const std::string set_layout_features_getReactionGlyphId(Layout* layout, const std::string reactionId) {
std::string reactionGlyphId = "";
int reactionGlyphIndex = 1;
int reactionGlyphIndex = 0;
std::vector<ReactionGlyph*> reactionGlyphs = getAssociatedReactionGlyphsWithReactionId(layout, reactionId);
while (true) {
reactionGlyphId = reactionId + "_Glyph_" + std::to_string(reactionGlyphIndex++);
Expand All @@ -401,9 +401,9 @@ const std::string set_layout_features_getReactionGlyphId(Layout* layout, const s

const std::string set_layout_features_getSpeciesReferenceGlyphId(ReactionGlyph* reactionGlyph, const std::string speciesGlyphId, unsigned int stoichiometryIndex) {
std::string speciesReferenceGlyphId = "";
int speciesReferenceGlyphIndex = 1;
int speciesReferenceGlyphIndex = 0;
std::vector<SpeciesReferenceGlyph*> speciesReferenceGlyphs = getSpeciesReferenceGlyphs(reactionGlyph);
std::string stoichiometryPhrase = "_Stoichiometry_" + std::to_string(stoichiometryIndex + 1);
std::string stoichiometryPhrase = "_Stoichiometry_" + std::to_string(stoichiometryIndex);
while (true) {
speciesReferenceGlyphId = speciesGlyphId + "_" + reactionGlyph->getId() + stoichiometryPhrase + "_Glyph_" + std::to_string(speciesReferenceGlyphIndex++);
bool isUniqueId = true;
Expand Down
46 changes: 23 additions & 23 deletions src/libsbmlnetwork_layout_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,18 @@ SimpleSpeciesReference* findSpeciesReference(Model* model, Layout* layout, React
return NULL;
}

bool containsSpecies(Model* model, Layout* layout, CompartmentGlyph* compartmentGlyph) {
std::string compartmentId = compartmentGlyph->getCompartmentId();
for (unsigned int i = 0; i < model->getNumSpecies(); i++)
if (model->getSpecies(i)->getCompartment() == compartmentId)
return true;

return false;
ReactionGlyph* findSpeciesReferenceReactionGlyph(Layout* layout, SpeciesReferenceGlyph* speciesReferenceGlyph) {
if (layout) {
for (unsigned int i = 0; i < layout->getNumReactionGlyphs(); i++) {
ReactionGlyph* reactionGlyph = layout->getReactionGlyph(i);
for (unsigned int j = 0; j < reactionGlyph->getNumSpeciesReferenceGlyphs(); j++) {
if (reactionGlyph->getSpeciesReferenceGlyph(j) == speciesReferenceGlyph)
return reactionGlyph;
}
}
}

return NULL;
}

bool compartmentGlyphBelongs(CompartmentGlyph* compartmentGlyph, Compartment* compartment) {
Expand Down Expand Up @@ -339,19 +344,6 @@ bool textGlyphBelongs(TextGlyph* textGlyph, GraphicalObject* graphicalObject) {
return false;
}

bool graphicalObjectBelongsToReactionGlyph(ReactionGlyph* reactionGlyph, GraphicalObject* graphicalObject) {
if (graphicalObject) {
for (unsigned int i = 0; i < reactionGlyph->getNumSpeciesReferenceGlyphs(); i++) {
if (reactionGlyph->getSpeciesReferenceGlyph(i) == graphicalObject)
return true;
else if (reactionGlyph->getSpeciesReferenceGlyph(i)->getSpeciesGlyphId() == graphicalObject->getId())
return true;
}
}

return false;
}

std::vector<TextGlyph*> getAssociatedTextGlyphsWithGraphicalObject(Layout* layout, GraphicalObject* graphicalObject) {
std::vector<TextGlyph*> textGlyphs;
for (unsigned int i = 0; i < layout->getNumTextGlyphs(); i++) {
Expand Down Expand Up @@ -491,7 +483,7 @@ std::vector<SpeciesReferenceGlyph*> getSpeciesReferenceGlyphs(ReactionGlyph* rea

const std::string getTextGlyphUniqueId(Layout* layout, GraphicalObject* graphicalObject) {
std::string textGlyphUniqueId = "";
int textGlyphIndex = 1;
int textGlyphIndex = 0;
std::vector<TextGlyph*> textGlyphs = getAssociatedTextGlyphsWithGraphicalObject(layout, graphicalObject);
while (true) {
textGlyphUniqueId = graphicalObject->getId() + "_TextGlyph_" + std::to_string(textGlyphIndex++);
Expand Down Expand Up @@ -523,8 +515,16 @@ const bool layoutContainsGlyphs(Layout* layout) {
(layout->getNumReactionGlyphs() > 0);
}

const bool isGraphicalObject(SBase* sbase) {
return dynamic_cast<GraphicalObject*>(sbase) ? true : false;
const bool isGraphicalObject(SBase* sBase) {
return dynamic_cast<GraphicalObject*>(sBase) != nullptr;
}

const bool isUniUniReaction(Model* model, ReactionGlyph* reactionGlyph) {
return isUniUniReaction(findReactionGlyphReaction(model, reactionGlyph));
}

const bool isUniUniReaction(Reaction* reaction) {
return reaction && reaction->getNumReactants() == 1 && reaction->getNumProducts() == 1;
}

const int getStoichiometryAsInteger(SimpleSpeciesReference* speciesReference) {
Expand Down
8 changes: 6 additions & 2 deletions src/libsbmlnetwork_layout_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ Reaction* findReactionGlyphReaction(Model* model, ReactionGlyph* reactionGlyph);

SimpleSpeciesReference* findSpeciesReference(Model* model, Layout* layout, ReactionGlyph* reactionGlyph, SpeciesGlyph* speciesGlyph);

ReactionGlyph* findSpeciesReferenceReactionGlyph(Layout* layout, SpeciesReferenceGlyph* speciesReferenceGlyph);

bool containsSpecies(Model* model, Layout* layout, CompartmentGlyph* compartmentGlyph);

bool compartmentGlyphBelongs(CompartmentGlyph* compartmentGlyph, Compartment* compartment);
Expand All @@ -78,8 +80,6 @@ const std::string getSpeciesReferenceGlyphSpeciesId(Layout* layout, SpeciesRefer

bool textGlyphBelongs(TextGlyph* textGlyph, GraphicalObject* graphicalObject);

bool graphicalObjectBelongsToReactionGlyph(Layout* layout, ReactionGlyph* reactionGlyph, GraphicalObject* graphicalObject);

std::vector<TextGlyph*> getAssociatedTextGlyphsWithGraphicalObject(Layout* layout, GraphicalObject* graphicalObject);

GraphicalObject* getGraphicalObjectUsingItsOwnId(Layout* layout, const std::string& graphicalObjectId);
Expand Down Expand Up @@ -110,6 +110,10 @@ const bool layoutContainsGlyphs(Layout* layout);

const bool isGraphicalObject(SBase* sbase);

const bool isUniUniReaction(Model* model, ReactionGlyph* reactionGlyph);

const bool isUniUniReaction(Reaction* reaction);

const int getStoichiometryAsInteger(SimpleSpeciesReference* speciesReference);

void updateAssociatedTextGlyphsPositionX(Layout* layout, GraphicalObject* graphicalObject, const double& movedDistanceX);
Expand Down

0 comments on commit 4be22c2

Please sign in to comment.