From: <xb...@us...> - 2013-07-13 08:46:29
|
Revision: 1848 http://sourceforge.net/p/scstudio/code/1848 Author: xborza Date: 2013-07-13 08:46:21 +0000 (Sat, 13 Jul 2013) Log Message: ----------- added OrderShapes automatic snapping; removed bug - if the coregion was too wide, the message didn't snap to it (picture bottom) | | | | | | <---- | | | | | | | Modified Paths: -------------- trunk/src/view/visio/addon/addon.cpp trunk/src/view/visio/addon/addon.h trunk/src/view/visio/addon/document.cpp trunk/src/view/visio/addon/messageSnapping.cpp trunk/src/view/visio/addon/messageSnapping.h Modified: trunk/src/view/visio/addon/addon.cpp =================================================================== --- trunk/src/view/visio/addon/addon.cpp 2013-07-13 08:31:01 UTC (rev 1847) +++ trunk/src/view/visio/addon/addon.cpp 2013-07-13 08:46:21 UTC (rev 1848) @@ -28,6 +28,7 @@ #include "errors.h" #include "resource.h" #include "pageutils.h" +#include "orderSnapping.h" #include "messageSnapping.h" #include "messageJump.h" @@ -80,8 +81,11 @@ m_bCoorX = false; m_bCoorY = false; m_bResnaping = false; + m_bOrderSnap = false; + m_iJumpType = 0; - m_iJumpType = 0; + last_selected = ST_UNKNOWN; + }; VAORC CStudioAddon::About(LPVAOV2LSTRUCT pV2L) @@ -593,7 +597,7 @@ void CStudioAddon::HandleCellChanged(Visio::IVCellPtr vsoCell) { - if(m_bResnaping) + if(m_bResnaping || COrderSnapping::m_bOrderSnap) return; // ignore events when undoing or redoing @@ -640,6 +644,13 @@ //Message snapping if(!m_bSnap) m_bSnap = true; } + + if(get_shape_type(vsoShape) == ST_BMSC_ORDER_ARROW || + get_shape_type(vsoShape) == ST_BMSC_ORDER_LINE) + { + if(!m_bOrderSnap) m_bOrderSnap = true; + } + m_bShapeChanged = true; } @@ -885,6 +896,8 @@ Visio::IVShapePtr shape = selection->Item[1]; m_mouseRelPosX = m_mousePosX - shape->Cells["PinX"]->Result[""]; m_mouseRelPosY = m_mousePosY - shape->Cells["PinY"]->Result[""]; + //check if selected shape is ordering + last_selected = get_shape_type(shape); } m_oldSelections[vsoApp] = m_curSelections[vsoApp]; @@ -930,9 +943,35 @@ m_iJumpType = 0; instances.clear(); } + //////////////////////////////////////////////////// + #define _u(x) CPageUtils::ConvertUnits(vsoApp, x, 0, visPageUnits) + //OrderShape snapping + if((selection->Count==1) && (last_selected==ST_BMSC_ORDER_ARROW || last_selected==ST_BMSC_ORDER_LINE) + && (m_bBeginChanged || m_bEndChanged) && !COrderSnapping::m_bOrderSnap) + { + Visio::IVShapePtr orderShape = selection->Item[1]; + + if(orderShape) + { + // really need mousePos too?... + double posX = CShapeUtils::getShapeCell(orderShape,"PinX")/*+_u(m_mouseRelPosX)*/; + double posY = CShapeUtils::getShapeCell(orderShape,"PinY")/*+_u(m_mouseRelPosX)*/; + + if(m_bBeginChanged && m_bEndChanged) // Moving whole orderShape + { + COrderSnapping::snapToCoregEvents(orderShape,posX,posY); + } + else if(m_bBeginChanged || m_bEndChanged) // Moving only one endpoint + { + COrderSnapping::snapEndpointToNearestEvent(orderShape,posX,posY,m_bBeginChanged ? "BeginX" : "EndX"); + } + m_bOrderSnap = m_bEndChanged = m_bShapeChanged = false; + } + } + + //////////////////////////////////////////////////// //Message snapping -#define _u(x) CPageUtils::ConvertUnits(vsoApp, x, 0, visPageUnits) if(!m_bOnDropShape && m_bSnap && !m_bKeyDown && (selection->Count == 1) && CMessageSnapping::isEnabled()) { Visio::IVShapePtr msgShape = selection->Item[1]; Modified: trunk/src/view/visio/addon/addon.h =================================================================== --- trunk/src/view/visio/addon/addon.h 2013-07-13 08:31:01 UTC (rev 1847) +++ trunk/src/view/visio/addon/addon.h 2013-07-13 08:46:21 UTC (rev 1848) @@ -147,6 +147,8 @@ std::map<long, Visio::IVSelectionPtr> m_curSelections; std::map<long, double> m_prevMousePosX; std::map<long, double> m_prevMousePosY; + + enum TShapeType last_selected; //Message numbering bool m_bMessageTextEdited; @@ -168,6 +170,8 @@ double m_mouseRelPosY; std::vector<Visio::IVShapePtr> instances; + bool m_bOrderSnap; + //Message jumping int m_iJumpType; }; Modified: trunk/src/view/visio/addon/document.cpp =================================================================== --- trunk/src/view/visio/addon/document.cpp 2013-07-13 08:31:01 UTC (rev 1847) +++ trunk/src/view/visio/addon/document.cpp 2013-07-13 08:46:21 UTC (rev 1848) @@ -35,6 +35,8 @@ #include "messageSnapping.h" #include "messageJump.h" +#include "orderSnapping.h" + #include <fstream> #include "data/msc.h" @@ -267,6 +269,8 @@ Visio::IVDocumentPtr vsoDocument = m_vsoApp->Documents->Item[iDocumentIndex]; Visio::IVShapePtr vsoShape = vsoDocument->Pages->Item[iPageIndex]->Shapes->ItemU[sShapeU]; + double posX, posY; + switch(get_shape_type(vsoShape)) { case ST_BMSC_INSTANCE: @@ -284,8 +288,8 @@ //Message snapping if(CMessageSnapping::isEnabled() && (m_vsoApp->ActiveWindow->Selection->Count == 1)) //Check whether snapping is enabled { - double posX = CShapeUtils::getShapeCell(vsoShape,"PinX"); - double posY = CShapeUtils::getShapeCell(vsoShape,"PinY"); + posX = CShapeUtils::getShapeCell(vsoShape,"PinX"); + posY = CShapeUtils::getShapeCell(vsoShape,"PinY"); if(m_addon->GetCtrlKeyDown()) posX += CPageUtils::ConvertUnits(m_vsoApp, m_addon->GetRelMousePosX(), 0, visPageUnits); @@ -293,6 +297,14 @@ } break; + case ST_BMSC_ORDER_LINE: + case ST_BMSC_ORDER_ARROW: + // orderShape snapping + posX = CShapeUtils::getShapeCell(vsoShape,"PinX"); + posY = CShapeUtils::getShapeCell(vsoShape,"PinY"); + COrderSnapping::snapToCoregEvents(vsoShape,posX,posY); + break; + case ST_COMMENT: case ST_TEXT: if(vsoShape->Text.length() == 0) Modified: trunk/src/view/visio/addon/messageSnapping.cpp =================================================================== --- trunk/src/view/visio/addon/messageSnapping.cpp 2013-07-13 08:31:01 UTC (rev 1847) +++ trunk/src/view/visio/addon/messageSnapping.cpp 2013-07-13 08:46:21 UTC (rev 1848) @@ -138,8 +138,8 @@ break; } - //Check whether point is only on instanceLine - if(!intPoint || !isPointOnInstancesLine(*intPoint, *it)) + //Check whether point is only on instanceLine -- what about coregion? + if(!intPoint || !isPointOnInstancesLine(*intPoint, *it, true)) continue; mouseDistX = msgSnapPointX - intPoint->get_x(); @@ -187,7 +187,7 @@ MsgConnectedEndpoints CMessageSnapping::glueMsgToInstancesPair(Visio::IVShapePtr msgShape, Visio::IVShapePtr leftInstance, Visio::IVShapePtr rightInstance, double yPos, MsgSnapType snapType, bool dontGlueIfConnected) -{ +{ int result = 0; //if there are no instances, return if(!leftInstance && !rightInstance) @@ -265,7 +265,9 @@ return false; //msgShape->Application->EventsEnabled = false; - msgShape->Cells[msgCell]->GlueToPos(instanceShape, msgOffset/sizeOfInstance, (double)xPos); + + Visio::IVCellPtr toGlue = msgShape->GetCells(msgCell); + toGlue->GlueToPos(instanceShape, msgOffset/sizeOfInstance, (double)xPos); //msgShape->Application->EventsEnabled = true; return true; @@ -322,8 +324,33 @@ return getIntersectionWithInstance(p2, p1, instanceShape, units); } -bool CMessageSnapping::isPointOnInstancesLine(const MscPoint& point, Visio::IVShapePtr instShape, VisUnitCodes units) +bool CMessageSnapping::isPointOnCoregion(const MscPoint& point, Visio::IVShapePtr coregShape) { + 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) + { + //calculate coreg begX -- BeginX is point in the middle +- width/2 + 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; +} + +bool CMessageSnapping::isPointOnInstancesLine(const MscPoint& point, Visio::IVShapePtr instShape, bool checkCoreg, VisUnitCodes units) +{ if(!instShape) return false; @@ -339,7 +366,27 @@ 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 - return !((msgOffset < InstOffset) || (msgOffset > (sizeOfInstance - InstOffset))); + 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; #undef _sp } Modified: trunk/src/view/visio/addon/messageSnapping.h =================================================================== --- trunk/src/view/visio/addon/messageSnapping.h 2013-07-13 08:31:01 UTC (rev 1847) +++ trunk/src/view/visio/addon/messageSnapping.h 2013-07-13 08:46:21 UTC (rev 1848) @@ -70,7 +70,12 @@ /** * */ - static bool isPointOnInstancesLine(const MscPoint& point, Visio::IVShapePtr instShape, VisUnitCodes units = visPageUnits); + static bool isPointOnInstancesLine(const MscPoint& point, Visio::IVShapePtr instShape,bool checkCoreg = false,VisUnitCodes units = visPageUnits); + + /* + * + */ + static bool isPointOnCoregion(const MscPoint& point, Visio::IVShapePtr coregShape); /** * Get Directional vector of given message shape */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |