Skip to content

Commit

Permalink
Merge pull request #7 from sys-bio/fix-bugs-and-add-new-features
Browse files Browse the repository at this point in the history
fix-bugs-and-add-new-features
  • Loading branch information
adelhpour authored Nov 12, 2024
2 parents 091479a + 3766dce commit 915074a
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 60 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
27 changes: 20 additions & 7 deletions src/autolayout/libsbmlnetwork_autolayout.cpp
Original file line number Diff line number Diff line change
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 @@ -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());
}
}
}

Expand Down Expand Up @@ -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) {
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

0 comments on commit 915074a

Please sign in to comment.