|
From: <tm...@us...> - 2013-07-13 08:31:11
|
Revision: 1847
http://sourceforge.net/p/scstudio/code/1847
Author: tmarton
Date: 2013-07-13 08:31:01 +0000 (Sat, 13 Jul 2013)
Log Message:
-----------
orderSnapping.cpp, orderSnapping.h added to solution and source files
Modified Paths:
--------------
trunk/src/view/visio/addon/scstudio.vcproj
Added Paths:
-----------
trunk/src/view/visio/addon/orderSnapping.cpp
trunk/src/view/visio/addon/orderSnapping.h
Added: trunk/src/view/visio/addon/orderSnapping.cpp
===================================================================
--- trunk/src/view/visio/addon/orderSnapping.cpp (rev 0)
+++ trunk/src/view/visio/addon/orderSnapping.cpp 2013-07-13 08:31:01 UTC (rev 1847)
@@ -0,0 +1,284 @@
+#include "stdafx.h"
+#include "dllmodule.h"
+#include "orderSnapping.h"
+#include "shapeUtils.h"
+#include "registryManager.h"
+
+bool COrderSnapping::m_bOrderSnap;
+
+COrderSnapping::SPoint COrderSnapping::get_connect_point(Visio::IVConnectPtr connect)
+{
+ SPoint result; // [visio internal units]
+ Visio::IVShapePtr shape = connect->ToSheet;
+
+ short cellrow = connect->ToCell->Row;
+ result.m_x = connect->ToCell->GetContainingRow()->Cell[0]->GetResult(70);
+ result.m_y = shape->CellsSRC[visSectionConnectionPts][cellrow][visY]->Result[0];
+
+ result.m_from_id = connect->FromSheet->ID;
+ result.m_to_id = connect->ToSheet->ID;
+
+ return result;
+}
+
+Visio::IVShapePtr COrderSnapping::getIntersectCoregion(Visio::IVShapePtr orderShape, double PinX,
+ double PinY, double max_dist)
+{
+ SPoint con1, con2;
+
+ con1.m_x = CShapeUtils::getShapeCell(orderShape,"BeginX");
+ con1.m_y = CShapeUtils::getShapeCell(orderShape,"BeginY");
+ con2.m_x = CShapeUtils::getShapeCell(orderShape,"EndX");
+ con2.m_y = CShapeUtils::getShapeCell(orderShape,"EndY");
+
+ bool side_side = con1.m_x == con2.m_x;
+
+ Visio::IVApplicationPtr vsoApp = orderShape->Application;
+ Visio::IVShapesPtr shapesOnPage = vsoApp->ActivePage->Shapes;
+
+ double coregBegX, coregEndX, coregBegY, coregEndY;
+
+ //Searches for instances on the page for the coregion matching the criteria
+ for(int i=1; i<=shapesOnPage->Count; i++)
+ {
+ Visio::IVShapePtr shape = shapesOnPage->Item[i];
+ if(get_shape_type(shape) == ST_BMSC_COREGION)
+ {
+ //calculate coreg begX -- BeginX is point in the middle +- width/2
+ double dif = CShapeUtils::getCoregionHeight(shape);
+
+ coregBegX = CShapeUtils::getShapeCell(shape, "BeginX") - dif;
+ coregEndX = CShapeUtils::getShapeCell(shape, "EndX") + dif;
+ coregBegY = CShapeUtils::getShapeCell(shape, "BeginY");
+ coregEndY = CShapeUtils::getShapeCell(shape, "EndY");
+
+ //check if PinX and PinY lie in coregion area
+ //toDo -- check it with some tolerance? Endpoints?
+ if(PinY <= coregBegY && PinY >= coregEndY &&
+ PinX >= coregBegX && PinX <= coregEndX )
+ {
+ return shape;
+ }
+ //if it's SIDE-SIDE from right, check snapping on left side (pinX is out od coreg)
+ if(side_side)
+ {
+ if(PinY <= coregBegY && PinY >= coregEndY &&
+ fabs(con1.m_x - coregBegX) <= max_dist)
+ {
+ return shape;
+ }
+ }
+ }
+ }
+ return NULL;
+}
+
+l_r_connects COrderSnapping::getCoregionsMsgConnectors(Visio::IVShapePtr coregion)
+{
+ l_r_connects result;
+
+ for(int i = 1; i <= coregion->FromConnects->Count; i++)
+ {
+ Visio::IVConnectPtr connect = coregion->FromConnects->Item[i];
+ //SPoint pos = get_connect_point(connect);
+ // shape connected to this point
+ Visio::IVShapePtr shape = connect->FromSheet;
+
+ // connect the message
+ TShapeType type = get_shape_type(shape);
+ if(type == ST_BMSC_MESSAGE || type == ST_BMSC_MESSAGE_FOUND || type == ST_BMSC_MESSAGE_LOST)
+ {
+ if( _tcsicmp(connect->ToCell->ContainingRow->Cell[1]->Formula, L"Height*1") == 0)
+ { //right side
+ result.second.push_back(connect);
+ }
+ else
+ { //left side
+ result.first.push_back(connect);
+ }
+ }
+ }
+ return result;
+}
+
+bool COrderSnapping::snapEndpointToNearestEvent(Visio::IVShapePtr orderShape, double PinX, double PinY, _bstr_t endPointX)
+{
+ // find related coregion
+ Visio::IVShapePtr coregion = getIntersectCoregion(orderShape, PinX, PinY, 10.0);
+ if(!coregion)
+ return false;
+
+ // find all connectors, to which the orderingShape can be snapped
+ l_r_connects connectors = getCoregionsMsgConnectors(coregion);
+ // on which side of coregion the Connection points are to find?
+ CorSide sideToLook;
+ SPoint conPoint;
+
+ if(_tcsicmp(endPointX,_T("BeginX")) == 0)
+ {
+ conPoint.m_x = CShapeUtils::getShapeCell(orderShape,"BeginX");
+ conPoint.m_y = CShapeUtils::getShapeCell(orderShape,"BeginY");
+ }
+ else if(_tcsicmp(endPointX,_T("EndX")) == 0)
+ {
+ conPoint.m_x = CShapeUtils::getShapeCell(orderShape,"EndX");
+ conPoint.m_y = CShapeUtils::getShapeCell(orderShape,"EndY");
+ }
+
+ // connector, to which endpoint should be glued
+ Visio::IVConnectPtr con;
+ double corCenter = CShapeUtils::getShapeCell(coregion,"BeginX");
+
+ // on which side glue the ordering endpoint?
+ if(corCenter > conPoint.m_x)
+ {
+ sideToLook = LEFT;
+ }
+ else
+ {
+ sideToLook = RIGHT;
+ }
+
+ // where it should be glued? -- 9999 == max - check the whole coregion area
+ con = getNearestMessageEvent(connectors,conPoint, sideToLook, 9999.9);
+ // Do snap and glue!
+ m_bOrderSnap = true;
+
+ bool res = false;
+ if(con != NULL)
+ {
+ Visio::IVCellPtr beg = orderShape->GetCells(endPointX);
+ beg->GlueTo(con->ToCell);
+ res = true;
+ }
+
+ m_bOrderSnap = false;
+ return res;
+}
+
+
+bool COrderSnapping::snapToCoregEvents(Visio::IVShapePtr orderShape, double PinX, double PinY)
+{
+ // find related coregion
+ Visio::IVShapePtr coregion = getIntersectCoregion(orderShape, PinX, PinY, 10.0);
+ if(!coregion)
+ return false;
+
+ // find all connectors, to which the orderingShape can be snapped
+ l_r_connects connectors = getCoregionsMsgConnectors(coregion);
+
+ // on which side of coregion the Connection points are to find?
+ CorSide sideToLook1, sideToLook2;
+ SPoint conPoint1, conPoint2;
+
+ conPoint1.m_x = CShapeUtils::getShapeCell(orderShape,"BeginX");
+ conPoint1.m_y = CShapeUtils::getShapeCell(orderShape,"BeginY");
+
+ conPoint2.m_x = CShapeUtils::getShapeCell(orderShape,"EndX");
+ conPoint2.m_y = CShapeUtils::getShapeCell(orderShape,"EndY");
+
+ // connectors, to which OrderShape should be glued
+ Visio::IVConnectPtr con1, con2;
+ double corCenter = CShapeUtils::getShapeCell(coregion,"BeginX");
+
+ // on which sides the ordering should be glued?
+ /* all ordering shapes except SIDE-SIDE are defaultly for events on different sides of coregion*/
+ if(conPoint1.m_x != conPoint2.m_x)
+ {
+ sideToLook1 = LEFT;
+ sideToLook2 = RIGHT;
+ }
+ else // SIDE-SIDE - check, on which side
+ {
+ if(corCenter > conPoint1.m_x)
+ {
+ sideToLook1 = sideToLook2 = LEFT;
+ }
+ else
+ {
+ sideToLook1 = sideToLook2 = RIGHT;
+ }
+ }
+
+ // where it should be glued? -- 9999 == max - check the whole coregion area
+ con1 = getNearestMessageEvent(connectors,conPoint1, sideToLook1, 9999.9);
+ con2 = getNearestMessageEvent(connectors,conPoint2, sideToLook2, 9999.9);
+ //Do snap and glue!
+ m_bOrderSnap = true;
+
+ int ret = 0;
+ if(con1 != NULL)
+ {
+ Visio::IVCellPtr beg = orderShape->GetCells("BeginX");
+ beg->GlueTo(con1->ToCell);
+ ret++;
+ }
+
+ if(con2 != NULL && con1 != con2)
+ {
+ Visio::IVCellPtr end = orderShape->GetCells("EndX");
+ end->GlueTo(con2->ToCell);
+ ret++;
+ }
+ m_bOrderSnap = false;
+
+ // if its side-side to right side, change the orientation
+ if(ret == 2 && (sideToLook1 == sideToLook2 == RIGHT))
+ {
+ Visio::IVCellPtr geom = orderShape->CellsSRC[visSectionControls][visRowFirst][0];
+ double value = geom->Result[0]; // in mms
+ geom->Result[0] = -value;
+ }
+
+ return (ret > 0);
+}
+
+Visio::IVConnectPtr COrderSnapping::getNearestMessageEvent(l_r_connects& corConns, SPoint point,
+ CorSide side, double max_dist)
+{
+ Visio::IVConnectPtr result = NULL;
+ //lookup the vector of connectors
+ std::vector<Visio::IVConnectPtr> cons;
+ cons = (side == LEFT) ? corConns.first : corConns.second;
+
+ std::vector<Visio::IVConnectPtr>::iterator it, toDel;
+
+ double min, distance, con_point_y, coregBegY = 0;
+ min = max_dist;
+ // coregions BeginY coordinate
+ if(!cons.empty())
+ {
+ coregBegY = CShapeUtils::getShapeCell(cons[0]->ToSheet,"BeginY");
+ }
+ else
+ {
+ return NULL;
+ }
+
+ for(it = cons.begin(); it != cons.end(); it++)
+ {
+ // get y coordinate in coregion coordinates (70 = milimeters)
+ con_point_y = (*it)->ToCell->GetContainingRow()->Cell[0]->GetResult(70);
+ // get y coordinate in global coordinate system
+ con_point_y = coregBegY-con_point_y;
+
+ distance = fabs(point.m_y - con_point_y);
+ if(distance <= min)
+ {
+ min = distance;
+ toDel = it;
+ result = *it;
+ }
+ }
+ // remove used conPoint from vector (to not use it in the future)
+ /*if(side == LEFT && min != max_dist)
+ {
+ corConns.first.erase(toDel);
+ }
+ else if(side == RIGHT && min != max_dist)
+ {
+ corConns.second.erase(toDel);
+ }*/
+
+ return result;
+}
\ No newline at end of file
Property changes on: trunk/src/view/visio/addon/orderSnapping.cpp
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: trunk/src/view/visio/addon/orderSnapping.h
===================================================================
--- trunk/src/view/visio/addon/orderSnapping.h (rev 0)
+++ trunk/src/view/visio/addon/orderSnapping.h 2013-07-13 08:31:01 UTC (rev 1847)
@@ -0,0 +1,74 @@
+/*
+ * 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) 2013 Viktor Borza <vic...@gm...>
+ *
+ * $Id$
+ */
+#pragma once
+
+#include <utility>
+#include <vector>
+#include "enums.h"
+#include "extract.h"
+#include "pageutils.h"
+
+typedef boost::shared_ptr<MscPoint> MscPointPtr;
+
+typedef std::pair<std::vector<Visio::IVConnectPtr>,std::vector<Visio::IVConnectPtr>> l_r_connects;
+
+class COrderSnapping
+{
+public:
+
+ struct SPoint
+ {
+ double m_x;
+ double m_y;
+
+ long m_from_id;
+ long m_to_id;
+
+ bool operator < (const SPoint& p2) const
+ {
+ int resy = fcmp(m_y, p2.m_y);
+ return resy < 0 || (resy == 0 && fcmp(m_x, p2.m_x) < 0);
+ }
+ };
+
+ enum CorSide
+ {
+ LEFT = 0,
+ RIGHT
+ };
+
+ static bool m_bOrderSnap;
+
+ static SPoint get_connect_point(Visio::IVConnectPtr connect);
+
+ /*take into account PinX and PinY, as well as endpoints and max distance from coregion*/
+ static Visio::IVShapePtr getIntersectCoregion(Visio::IVShapePtr orderShape,double PinX,
+ double PinY,double max_dist=3.0);
+
+ static Visio::IVConnectPtr getNearestMessageEvent(l_r_connects& coregionConnectors,
+ SPoint point, CorSide side,double max_dist=3.0);
+
+ static l_r_connects getCoregionsMsgConnectors(Visio::IVShapePtr coregion);
+
+ static bool snapToCoregEvents(Visio::IVShapePtr orderShape, double PinX, double PinY);
+
+ /* use only for endpoints snapping -- global functionality, not intern*/
+ static bool snapEndpointToNearestEvent(Visio::IVShapePtr shape, double pinX, double pinY, _bstr_t endPointX);
+};
+
+// $Id$
\ No newline at end of file
Property changes on: trunk/src/view/visio/addon/orderSnapping.h
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/src/view/visio/addon/scstudio.vcproj
===================================================================
--- trunk/src/view/visio/addon/scstudio.vcproj 2013-07-09 22:45:14 UTC (rev 1846)
+++ trunk/src/view/visio/addon/scstudio.vcproj 2013-07-13 08:31:01 UTC (rev 1847)
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
- Version="9,00"
+ Version="9.00"
Name="scstudio"
ProjectGUID="{0E00282C-F48B-4984-A274-5B59E1E2AD49}"
RootNamespace="scstudio"
@@ -332,6 +332,14 @@
>
</File>
<File
+ RelativePath=".\orderSnapping.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\orderSnapping.h"
+ >
+ </File>
+ <File
RelativePath=".\registryManager.cpp"
>
</File>
@@ -678,11 +686,11 @@
>
</File>
<File
- RelativePath=".\intervals.bmp"
+ RelativePath="..\..\..\..\..\..\bitmaps\intervals.bmp"
>
</File>
<File
- RelativePath="..\..\..\..\..\..\bitmaps\intervals.bmp"
+ RelativePath=".\intervals.bmp"
>
</File>
<File
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|