From: <xb...@us...> - 2013-07-13 13:40:26
|
Revision: 1849 http://sourceforge.net/p/scstudio/code/1849 Author: xborza Date: 2013-07-13 13:40:24 +0000 (Sat, 13 Jul 2013) Log Message: ----------- message snapping to wrong side in wide coregions solved Modified Paths: -------------- trunk/src/view/visio/addon/messageSnapping.cpp trunk/src/view/visio/addon/messageSnapping.h Modified: trunk/src/view/visio/addon/messageSnapping.cpp =================================================================== --- trunk/src/view/visio/addon/messageSnapping.cpp 2013-07-13 08:46:21 UTC (rev 1848) +++ trunk/src/view/visio/addon/messageSnapping.cpp 2013-07-13 13:40:24 UTC (rev 1849) @@ -138,16 +138,24 @@ break; } - //Check whether point is only on instanceLine -- what about coregion? - if(!intPoint || !isPointOnInstancesLine(*intPoint, *it, true)) + //Check whether point is only on instanceLine or on coregion + bool mes_in_coreg = false; + + if(!(intPoint && (isPointOnInstancesLine(*intPoint, *it) || isPointOnCoregion(*intPoint, *it)))) continue; + //check if Message SnapPoints lies in Coregion area + MscPoint point; + point.set_x(msgSnapPointX); + point.set_y(msgSnapPointY); + mes_in_coreg = isPointInCoregionArea(point, *it); + mouseDistX = msgSnapPointX - intPoint->get_x(); distance = sqrt(pow((msgSnapPointX - intPoint->get_x()),2) + pow((msgSnapPointY - intPoint->get_y()),2)); delete intPoint; - if(mouseDistX < 0) + if((mouseDistX < 0 && !mes_in_coreg) || (mes_in_coreg && mouseDistX > 0 && !rightClosestInstance)) { if(!rightClosestInstance || distance < rightClosestInstanceDist) { @@ -155,7 +163,7 @@ rightClosestInstanceDist = distance; } } - else if(mouseDistX > 0) + else if((mouseDistX > 0 && !mes_in_coreg) || (mes_in_coreg && mouseDistX < 0 && !leftClosestInstance)) { if(!leftClosestInstance || distance < leftClosestInstanceDist) { @@ -324,32 +332,59 @@ return getIntersectionWithInstance(p2, p1, instanceShape, units); } -bool CMessageSnapping::isPointOnCoregion(const MscPoint& point, Visio::IVShapePtr coregShape) +bool CMessageSnapping::isPointInCoregionArea(const MscPoint& point, Visio::IVShapePtr instShape) { double coregBegX, coregEndX, coregBegY, coregEndY; - //Searches for instances on the page for the coregion matching the criteria - if(get_shape_type(coregShape) == ST_BMSC_COREGION) + std::vector<Visio::IVShapePtr> cor = CShapeUtils::getConnectedShapes(instShape, ST_BMSC_COREGION); + for(u_int i=0; i<cor.size(); i++) { - //calculate coreg begX -- BeginX is point in the middle +- width/2 - double dif = CShapeUtils::getCoregionHeight(coregShape); + Visio::IVShapePtr coregShape = cor.at(i); - coregBegX = CShapeUtils::getShapeCell(coregShape, "BeginX") - dif; + double dif = CShapeUtils::getCoregionHeight(coregShape); + coregBegX = CShapeUtils::getShapeCell(coregShape, "BeginX") - dif; coregEndX = CShapeUtils::getShapeCell(coregShape, "EndX") + dif; coregBegY = CShapeUtils::getShapeCell(coregShape, "BeginY"); - coregEndY = CShapeUtils::getShapeCell(coregShape, "EndY"); + coregEndY = CShapeUtils::getShapeCell(coregShape, "EndY"); - //check if MscPoint lies on one of the coregion's sides + //check if MscPoint lies on one of the coregion's sides bool x_coordinate = false, y_coordinate = false; + x_coordinate = point.get_x() > coregBegX && point.get_x() < coregEndX; + y_coordinate = point.get_y() < coregBegY && point.get_y() > coregEndY; + + if(x_coordinate && y_coordinate) + return true; + } + return false; +} + +bool CMessageSnapping::isPointOnCoregion(const MscPoint& point, Visio::IVShapePtr instShape) +{ + double coregBegX, coregEndX, coregBegY, coregEndY; + + std::vector<Visio::IVShapePtr> cor = CShapeUtils::getConnectedShapes(instShape, ST_BMSC_COREGION); + for(u_int i=0; i<cor.size(); i++) + { + Visio::IVShapePtr coregShape = cor.at(i); + + double dif = CShapeUtils::getCoregionHeight(coregShape); + coregBegX = CShapeUtils::getShapeCell(coregShape, "BeginX") - dif; + coregEndX = CShapeUtils::getShapeCell(coregShape, "EndX") + dif; + coregBegY = CShapeUtils::getShapeCell(coregShape, "BeginY"); + coregEndY = CShapeUtils::getShapeCell(coregShape, "EndY"); + + //check if MscPoint lies on one of the coregion's sides + bool x_coordinate = false, y_coordinate = false; x_coordinate = fabs(point.get_x() - coregBegX) < 0.01 || fabs(point.get_x() - coregEndX) < 0.01; y_coordinate = point.get_y() <= coregBegY && point.get_y() >= coregEndY; - return x_coordinate && y_coordinate; - } - return false; + if(x_coordinate && y_coordinate) + return true; + } + return false; } -bool CMessageSnapping::isPointOnInstancesLine(const MscPoint& point, Visio::IVShapePtr instShape, bool checkCoreg, VisUnitCodes units) +bool CMessageSnapping::isPointOnInstancesLine(const MscPoint& point, Visio::IVShapePtr instShape, VisUnitCodes units) { if(!instShape) return false; @@ -366,27 +401,7 @@ double msgOffset = sqrt( pow(point.get_x() - _sp("BeginX"),2) + pow(point.get_y() - _sp("BeginY"),2) ); //Glue to position, if message is on "rectangles" on the instance it won't be glued - bool onInstance = false; - onInstance = !((msgOffset < InstOffset) || (msgOffset > (sizeOfInstance - InstOffset))); - - if(!checkCoreg) - { - return onInstance; - } - else // check the connected coregions - { - bool onCoreg = false; - std::vector<Visio::IVShapePtr> cor = CShapeUtils::getConnectedShapes(instShape, ST_BMSC_COREGION); - for(u_int i=0; i<cor.size(); i++) - { - if(onCoreg = isPointOnCoregion(point,cor.at(i))) - { - break; - } - } - return onInstance || onCoreg; - } - return false; + return !((msgOffset < InstOffset) || (msgOffset > (sizeOfInstance - InstOffset))); #undef _sp } Modified: trunk/src/view/visio/addon/messageSnapping.h =================================================================== --- trunk/src/view/visio/addon/messageSnapping.h 2013-07-13 08:46:21 UTC (rev 1848) +++ trunk/src/view/visio/addon/messageSnapping.h 2013-07-13 13:40:24 UTC (rev 1849) @@ -70,13 +70,18 @@ /** * */ - static bool isPointOnInstancesLine(const MscPoint& point, Visio::IVShapePtr instShape,bool checkCoreg = false,VisUnitCodes units = visPageUnits); + static bool isPointOnInstancesLine(const MscPoint& point, Visio::IVShapePtr instShape,VisUnitCodes units = visPageUnits); /* - * + * Check all coregions boundaries in instance, if it contains MSCpint */ - static bool isPointOnCoregion(const MscPoint& point, Visio::IVShapePtr coregShape); + static bool isPointOnCoregion(const MscPoint& point, Visio::IVShapePtr instShape); + /** + * Check all coregions on instance, if it contains MSCpint + */ + static bool isPointInCoregionArea(const MscPoint& point, Visio::IVShapePtr instShape); + /** * Get Directional vector of given message shape */ static bool getMsgVector(Visio::IVShapePtr msgShape, MscPoint* resultVector, VisUnitCodes units = visMillimeters); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |