|
From: <mbe...@us...> - 2010-07-09 11:02:16
|
Revision: 830
http://scstudio.svn.sourceforge.net/scstudio/?rev=830&view=rev
Author: mbezdeka
Date: 2010-07-09 11:02:10 +0000 (Fri, 09 Jul 2010)
Log Message:
-----------
message snapping files added
Added Paths:
-----------
trunk/src/view/visio/addon/messageSnapping.cpp
trunk/src/view/visio/addon/messageSnapping.h
Added: trunk/src/view/visio/addon/messageSnapping.cpp
===================================================================
--- trunk/src/view/visio/addon/messageSnapping.cpp (rev 0)
+++ trunk/src/view/visio/addon/messageSnapping.cpp 2010-07-09 11:02:10 UTC (rev 830)
@@ -0,0 +1,146 @@
+/*
+ * scstudio - Sequence Chart Studio
+ * http://scstudio.sourceforge.net
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * Copyright (c) 2010 Martin Bezdeka <mbe...@se...>
+ *
+ * $Id$
+ */
+
+#include "stdafx.h"
+#include "dllmodule.h"
+#include "messageSnapping.h"
+#include "shapeUtils.h"
+
+bool CMessageSnapping::isEnabled()
+{
+ const TCHAR* regFolder = _T("Software\\Sequence Chart Studio\\MessageSnapping");
+
+ if(!GetRegistry<bool>(regFolder, NULL, _T("SnapEnabled"), 0))
+ return false;
+
+ return true;
+}
+
+std::vector<Visio::IVShapePtr> CMessageSnapping::getIntersectInstances(Visio::IVShapePtr msgShape)
+{
+ std::vector<Visio::IVShapePtr> instShapes;
+ Visio::IVApplicationPtr vsoApp = msgShape->Application;
+ Visio::IVShapesPtr shapesOnPage = vsoApp->ActivePage->Shapes;
+
+ double InstBegY, InstEndY;
+ double msgPinY = CShapeUtils::GetShapeCellProperty(msgShape, "PinY", "mm");
+
+ for(int i=1; i<=shapesOnPage->Count; i++)
+ {
+ Visio::IVShapePtr shape = shapesOnPage->Item[i];
+ if(get_shape_type(shape) == ST_BMSC_INSTANCE)
+ {
+ InstBegY = CShapeUtils::GetShapeCellProperty(shape, "BeginY", "mm");
+ InstEndY = CShapeUtils::GetShapeCellProperty(shape, "EndY", "mm");
+
+ //If instance is upside down, swap coordinates
+ if((InstBegY - InstEndY) < 0)
+ std::swap(InstBegY, InstEndY);
+
+ //Check if the message intersect instance and put it into vector of instances matching the criteria
+ if((InstBegY > msgPinY) && (InstEndY < msgPinY))
+ instShapes.push_back(shape);
+ }
+ }
+
+ return instShapes;
+}
+
+std::pair<Visio::IVShapePtr, Visio::IVShapePtr> CMessageSnapping::getClosestInstancePair(Visio::IVShapePtr msgShape,
+ const std::vector<Visio::IVShapePtr>& instances)
+{
+ //FIX ME: sometimes doesn't find the closest instances
+ double msgPinX = CShapeUtils::GetShapeCellProperty(msgShape, "PinX", "mm");
+
+ Visio::IVShapePtr leftClosestInstance = NULL;
+ Visio::IVShapePtr rightClosestInstance = NULL;
+ double leftClosestInstanceDist = 0;
+ double rightClosestInstanceDist = 0;
+ double instPinX;
+ double distance;
+
+ for(std::vector<Visio::IVShapePtr>::const_iterator it = instances.begin(); it != instances.end(); it++)
+ {
+ instPinX = CShapeUtils::GetShapeCellProperty((*it),"PinX","mm");
+ distance = msgPinX - instPinX;
+ (*it)->Text = stringize() << distance << " - ID: " << (*it)->ID;
+ if(distance < 0)
+ {
+ if(!rightClosestInstance || distance > rightClosestInstanceDist) //NOTE: Distance must be bigger, becaouse numbers are negative
+ {
+ rightClosestInstance = (*it);
+ rightClosestInstanceDist = distance;
+ }
+ }
+ else
+ {
+ if(!leftClosestInstance || distance < leftClosestInstanceDist)
+ {
+ leftClosestInstance = (*it);
+ leftClosestInstanceDist = distance;
+ }
+ }
+ }
+
+ return std::pair<Visio::IVShapePtr, Visio::IVShapePtr>(leftClosestInstance,rightClosestInstance);
+}
+
+void CMessageSnapping::glueMsgToInstances(Visio::IVShapePtr msgShape, Visio::IVShapePtr leftInstance, Visio::IVShapePtr rightInstance)
+{
+ double msgPinY = CShapeUtils::GetShapeCellProperty(msgShape, "PinY", "mm");
+
+ //reverse instances if message is left headed arrow
+ if((CShapeUtils::GetShapeCellProperty(msgShape, "EndX", "mm") - CShapeUtils::GetShapeCellProperty(msgShape, "BeginX", "mm")) < 0)
+ {
+ Visio::IVShapePtr buffer = leftInstance;
+ leftInstance = rightInstance;
+ rightInstance = buffer;
+ }
+
+ //restrict snapping for FOUND and LOST messages
+ switch(get_shape_type(msgShape))
+ {
+ case ST_BMSC_MESSAGE_FOUND:
+ leftInstance = NULL;
+ break;
+ case ST_BMSC_MESSAGE_LOST:
+ rightInstance = NULL;
+ break;
+ }
+
+ //Glue to left instance
+ if(leftInstance)
+ {
+ double InstBegY = CShapeUtils::GetShapeCellProperty(leftInstance, "BeginY", "mm");
+ double InstEndY = CShapeUtils::GetShapeCellProperty(leftInstance, "EndY", "mm");
+ double sizeOfInstance = InstBegY - InstEndY;
+ double msgOffset = InstBegY - msgPinY;
+ msgShape->Cells["BeginX"]->GlueToPos(leftInstance,msgOffset/sizeOfInstance,0.0);
+ }
+ //Glue to right instance
+ if(rightInstance)
+ {
+ double InstBegY = CShapeUtils::GetShapeCellProperty(rightInstance, "BeginY", "mm");
+ double InstEndY = CShapeUtils::GetShapeCellProperty(rightInstance, "EndY", "mm");
+ double sizeOfInstance = InstBegY - InstEndY;
+ double msgOffset = InstBegY - msgPinY;
+ msgShape->Cells["EndX"]->GlueToPos(rightInstance,msgOffset/sizeOfInstance,0.0);
+ }
+}
+
+// $Id$
\ No newline at end of file
Property changes on: trunk/src/view/visio/addon/messageSnapping.cpp
___________________________________________________________________
Added: svn:keywords
+ Id
Added: svn:eol-style
+ native
Added: trunk/src/view/visio/addon/messageSnapping.h
===================================================================
--- trunk/src/view/visio/addon/messageSnapping.h (rev 0)
+++ trunk/src/view/visio/addon/messageSnapping.h 2010-07-09 11:02:10 UTC (rev 830)
@@ -0,0 +1,45 @@
+/*
+ * scstudio - Sequence Chart Studio
+ * http://scstudio.sourceforge.net
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * Copyright (c) 2010 Martin Bezdeka <mbe...@se...>
+ *
+ * $Id$
+ */
+#pragma once
+
+#include <utility>
+#include <vector>
+
+class CMessageSnapping
+{
+public:
+
+ static bool isEnabled();
+ /*
+ * Get All instances that intersect HORIZONTAL line of current msg
+ * returns vector of pointers to instances, if zero, there are no intersecting instances
+ */
+ static std::vector<Visio::IVShapePtr> getIntersectInstances(Visio::IVShapePtr msgShape);
+ /*
+ * returns two closest instances for given message (first of the pair is instance on the left from the message, second is ono the right)
+ */
+ static std::pair<Visio::IVShapePtr, Visio::IVShapePtr> getClosestInstancePair(Visio::IVShapePtr msgShape, const std::vector<Visio::IVShapePtr>& instances);
+ /*
+ * Glue given message on the given instances, message
+ * designed only for horizontal messages (diagonal messages will be snapped according their PinX point and reformed to horizontal messages)
+ */
+ static void glueMsgToInstances(Visio::IVShapePtr msgShape, Visio::IVShapePtr leftInstance, Visio::IVShapePtr rightInstance);
+
+};
+
+// $Id$
\ No newline at end of file
Property changes on: trunk/src/view/visio/addon/messageSnapping.h
___________________________________________________________________
Added: svn:keywords
+ Id
Added: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|