From a484fd9f82c73983c19d872bb54f0924ba541802 Mon Sep 17 00:00:00 2001 From: adelhpour Date: Mon, 11 Nov 2024 22:14:38 -0800 Subject: [PATCH 1/2] 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 c08b0630..a2fbbb4e 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 a91d992f..b53bdf94 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 5ca816d2..9a9d1f5b 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 2/2] 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 60a2d3e9..44bb5d1f 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