Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/sys-bio/SBMLNetwork into…
Browse files Browse the repository at this point in the history
… develop
  • Loading branch information
luciansmith committed Nov 12, 2024
2 parents ce483eb + 915074a commit e49f7f0
Show file tree
Hide file tree
Showing 19 changed files with 475 additions and 153 deletions.
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.4.0
0.4.1
50 changes: 34 additions & 16 deletions src/autolayout/libsbmlnetwork_autolayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -189,22 +193,27 @@ 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<std::string> extentsInitializedCompartmentGlyphIds;
for (int i = 0; i < layout->getNumSpeciesGlyphs(); i++) {
Compartment *compartment = findSpeciesGlyphCompartment(model, layout->getSpeciesGlyph(i));
if (compartment) {
std::vector < CompartmentGlyph * > compartmentGlyphs = getAssociatedCompartmentGlyphsWithCompartmentId(
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());
}
Expand All @@ -213,9 +222,14 @@ void updateCompartmentExtentsUsingItsElementsExtents(Model *model, Layout *layou
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());
}
}
}

Expand Down Expand Up @@ -280,7 +294,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") {
Expand Down Expand Up @@ -324,7 +338,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;
Expand Down Expand Up @@ -375,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) {
Expand Down
6 changes: 3 additions & 3 deletions src/autolayout/libsbmlnetwork_autolayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
120 changes: 72 additions & 48 deletions src/autolayout/libsbmlnetwork_autolayout_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand All @@ -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();
Expand All @@ -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;
}
6 changes: 2 additions & 4 deletions src/autolayout/libsbmlnetwork_autolayout_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};

Expand Down
Loading

0 comments on commit e49f7f0

Please sign in to comment.