|
From: <mbe...@us...> - 2010-07-23 09:04:18
|
Revision: 838
http://scstudio.svn.sourceforge.net/scstudio/?rev=838&view=rev
Author: mbezdeka
Date: 2010-07-23 09:04:12 +0000 (Fri, 23 Jul 2010)
Log Message:
-----------
Message snapping
- bugs fixed
Modified Paths:
--------------
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/document.cpp
===================================================================
--- trunk/src/view/visio/addon/document.cpp 2010-07-23 00:03:47 UTC (rev 837)
+++ trunk/src/view/visio/addon/document.cpp 2010-07-23 09:04:12 UTC (rev 838)
@@ -264,19 +264,19 @@
if(vsoShape->Text.length() == 0)
vsoShape->Text = _T("NAME");
- if(CMessageSnapping::isEnabled()) //Check whether snapping is enabled
+ if(CMessageSnapping::isEnabled() && (m_vsoApp->ActiveWindow->Selection->Count == 1)) //Check whether snapping is enabled
+ {
+ double posX = CShapeUtils::GetShapeCellProperty(vsoShape,"PinX",visPageUnits), posY = CShapeUtils::GetShapeCellProperty(vsoShape,"PinY",visPageUnits);
+ if(m_addon->GetCtrlKeyDown())
{
- double posX = CShapeUtils::GetShapeCellProperty(vsoShape,"PinX",visPageUnits), posY = CShapeUtils::GetShapeCellProperty(vsoShape,"PinY",visPageUnits);
- if(m_addon->GetCtrlKeyDown())
- {
- posX += CPageUtils::ConvertUnits(m_vsoApp, m_addon->GetRelMousePosX(), 0, visPageUnits);
- posY += CPageUtils::ConvertUnits(m_vsoApp, m_addon->GetRelMousePosY(), 0, visPageUnits);
- }
- m_vsoApp->EventsEnabled = false;
- autoSnapping(vsoShape,posX, posY);
- m_vsoApp->EventsEnabled = true;
+ posX += CPageUtils::ConvertUnits(m_vsoApp, m_addon->GetRelMousePosX(), 0, visPageUnits);
+ posY += CPageUtils::ConvertUnits(m_vsoApp, m_addon->GetRelMousePosY(), 0, visPageUnits);
}
- autoEnumerate(vsoShape);
+ m_vsoApp->EventsEnabled = false;
+ autoSnapping(vsoShape,posX, posY);
+ m_vsoApp->EventsEnabled = true;
+ }
+ autoEnumerate(vsoShape);
break;
case ST_COMMENT:
@@ -2204,7 +2204,7 @@
closestInst = CMessageSnapping::getClosestInstancePair(msgShape, posX, posY, instShapes, snapType);
//Step 5:Glue to them
- CMessageSnapping::glueMsgToInstancesPair(msgShape, closestInst.first, closestInst.second,posY, snapType);
+ CMessageSnapping::glueMsgToInstancesPair(msgShape, closestInst.first, closestInst.second, posY, snapType);
//Step 6: Do some corrections
if(closestInst.first ^ closestInst.second)
Modified: trunk/src/view/visio/addon/messageSnapping.cpp
===================================================================
--- trunk/src/view/visio/addon/messageSnapping.cpp 2010-07-23 00:03:47 UTC (rev 837)
+++ trunk/src/view/visio/addon/messageSnapping.cpp 2010-07-23 09:04:12 UTC (rev 838)
@@ -125,7 +125,8 @@
break;
}
- if(!intPoint || intPoint->y > instBeginY || intPoint->y < instEndY)
+ //Check whether point is only on instanceLine
+ if(!intPoint || intPoint->y > instBeginY || intPoint->y < instEndY || !isPointOnInstancesLine(*intPoint, *it))
continue;
mouseDistX = msgSnapPointX - intPoint->x;
@@ -173,7 +174,7 @@
}
void CMessageSnapping::glueMsgToInstancesPair(Visio::IVShapePtr msgShape, Visio::IVShapePtr leftInstance, Visio::IVShapePtr rightInstance,
- double yPos, MsgSnapType snapType)
+ double yPos, MsgSnapType snapType)
{
//if there are no instances, return
if(!leftInstance && !rightInstance)
@@ -235,11 +236,6 @@
void CMessageSnapping::glueMsgToInstance(Visio::IVShapePtr msgShape, Visio::IVShapePtr instanceShape,
const _bstr_t & msgCell, double yPos)
{
- //Get values from cells
- double InstOffsetLeft = 0;
- if(instanceShape->CellExists["Controls.mscHeadWidth"][visExistsAnywhere]) //NOTE: Check if the instance is not headless
- InstOffsetLeft = CShapeUtils::GetShapeCellProperty(instanceShape, "Controls.mscHeadWidth.X", visPageUnits); //NOTE: get width of instances rectangles
-
double InstBegY = CShapeUtils::GetShapeCellProperty(instanceShape, "BeginY", visPageUnits);
double InstEndY = CShapeUtils::GetShapeCellProperty(instanceShape, "EndY", visPageUnits);
@@ -250,10 +246,6 @@
if(sizeOfInstance == 0)
return;
- //Glue to position, if message is on "rectangles" on the instance it won't be glued
- if((msgOffset < InstOffsetLeft) || (msgOffset > (sizeOfInstance - InstOffsetLeft)))
- return;
-
msgShape->Application->EventsEnabled = false;
msgShape->Cells[msgCell]->GlueToPos(instanceShape,msgOffset/sizeOfInstance,0.0);
msgShape->Application->EventsEnabled = true;
@@ -285,4 +277,30 @@
return result;
}
+bool CMessageSnapping::isPointOnInstancesLine(VEC2 point, Visio::IVShapePtr instShape)
+{
+#define _sp(x) CShapeUtils::GetShapeCellProperty(instShape, x, visPageUnits)
+
+ double InstOffset = 0;
+
+ //Get values from cells
+ if(instShape->CellExists["Controls.mscHeadWidth"][visExistsAnywhere]) //NOTE: Check if the instance is not headless
+ InstOffset = _sp("Controls.mscHeadWidth.X"); //NOTE: get width of instances rectangles
+
+ double sizeOfInstance = _sp("Width");
+ double msgOffset = sqrt( pow(point.x - _sp("BeginX"),2) + pow(point.y - _sp("BeginY"),2) );
+
+ //avoid division by zero - when instances are in horizontal position
+ if(sizeOfInstance == 0)
+ return false;
+
+ //Glue to position, if message is on "rectangles" on the instance it won't be glued
+ if((msgOffset < InstOffset) || (msgOffset > (sizeOfInstance - InstOffset)))
+ return false;
+
+ return true;
+
+#undef _sp
+}
+
// $Id$
\ No newline at end of file
Modified: trunk/src/view/visio/addon/messageSnapping.h
===================================================================
--- trunk/src/view/visio/addon/messageSnapping.h 2010-07-23 00:03:47 UTC (rev 837)
+++ trunk/src/view/visio/addon/messageSnapping.h 2010-07-23 09:04:12 UTC (rev 838)
@@ -47,7 +47,7 @@
* @param onlyOnInstanceLine if true avoid connection message on instace's "rectangles" on the top and the bottom
*/
static void glueMsgToInstancesPair(Visio::IVShapePtr msgShape, Visio::IVShapePtr leftInstance, Visio::IVShapePtr rightInstance,
- double yPos, MsgSnapType snapType);
+ double yPos, MsgSnapType snapType);
/*
* Glue given message to instance, but only to "line" of instance, rectangles at the bottom and top are ignored
* @param msgCell message cell which should be glued (e.g. BeginX, EndY)
@@ -56,6 +56,8 @@
static void glueMsgToInstance(Visio::IVShapePtr msgShape, Visio::IVShapePtr instanceShape, const _bstr_t & msgCell, double yPos);
static PVEC2 getIntersectionWithInstance(Visio::IVShapePtr msgShape, Visio::IVShapePtr instanceShape);
+
+ static bool isPointOnInstancesLine(VEC2 point, Visio::IVShapePtr instShape);
};
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|