[commit] r2051 - trunk/GME/Gme
GMESRC Repository Notifications
gme-commit at list.isis.vanderbilt.edu
Tue Sep 11 09:23:58 CDT 2012
Author: ksmyth
Date: Tue Sep 11 09:23:58 2012
New Revision: 2051
Log:
Use location and full size for ModelGrid instead of center point and half size to reduce rounding errors. Fixes crash in rare case, where objects can be exactly adjacent, and the autorouter wants to route between them
Modified:
trunk/GME/Gme/GMEOLEData.cpp
trunk/GME/Gme/GMEView.cpp
trunk/GME/Gme/GUIObject.cpp
trunk/GME/Gme/GUIObject.h
trunk/GME/Gme/ModelGrid.cpp
trunk/GME/Gme/ModelGrid.h
trunk/GME/Gme/PendingObjectPosRequest.cpp
trunk/GME/Gme/PendingObjectPosRequest.h
Modified: trunk/GME/Gme/GMEOLEData.cpp
==============================================================================
--- trunk/GME/Gme/GMEOLEData.cpp Tue Sep 11 09:23:38 2012 (r2050)
+++ trunk/GME/Gme/GMEOLEData.cpp Tue Sep 11 09:23:58 2012 (r2051)
@@ -136,14 +136,9 @@
// Emulate the grid.
long gs = GME_GRID_SIZE;
- align.x = (align.x % gs);
- align.y = (align.y % gs);
+ rect.MoveToXY(rect.left / gs * gs, rect.top / gs * gs);
-
- rect.OffsetRect(-align.x, -align.y);
- // rect.OffsetRect(-offset.x, -offset.y);
pDC->DrawFocusRect(&rect);
-
}
pos = annRects.GetHeadPosition();
Modified: trunk/GME/Gme/GMEView.cpp
==============================================================================
--- trunk/GME/Gme/GMEView.cpp Tue Sep 11 09:23:38 2012 (r2050)
+++ trunk/GME/Gme/GMEView.cpp Tue Sep 11 09:23:58 2012 (r2051)
@@ -3996,21 +3996,21 @@
obj = fco->dynamic_cast_CGuiObject();
if(!obj || !obj->IsVisible())
continue;
- CPoint pt = obj->GetLocation().CenterPoint();
if(!modelGrid.IsAvailable(obj)) {
- if(!modelGrid.GetClosestAvailable(obj,pt)) {
+ CRect loc = obj->GetLocation();
+ if(!modelGrid.GetClosestAvailable(obj, loc)) {
AfxMessageBox(_T("Too Many Models! Internal Program Error!"),MB_OK | MB_ICONSTOP);
EndWaitCursor();
return;
}
- // obj->SetCenter(pt);
+ // ASSERT(modelGrid.IsAvailable(loc));
if (!executingPendingRequests && !IsInstance()) {
- CPendingObjectPosRequest *req = new CPendingObjectPosRequest(obj, pt, obj->GetLocation(), obj->GetParentAspect());
+ CPendingObjectPosRequest *req = new CPendingObjectPosRequest(obj, loc, obj->GetParentAspect());
pendingRequests.AddHead(req);
postPendingRequestEvent = true;
}
- obj->SetCenter(pt, -1, false);
+ obj->SetObjectLocation(loc, -1, false);
}
modelGrid.Set(obj);
}
@@ -8867,15 +8867,15 @@
void CGMEView::SyncOnGrid(CGuiObject *obj, int aspectIndexFrom, int aspectIndexTo)
{
// aspectIndexTo might be equal with aspectIndexFrom
- CPoint center = obj->GetLocation(aspectIndexFrom).CenterPoint();//take the pos from the aspFrom (source) aspect
+ CRect loc = obj->GetLocation(aspectIndexFrom);//take the pos from the aspFrom (source) aspect
if (!modelGrid.IsAvailable(obj, aspectIndexFrom)) {//is enough space to occupy the pos taken from the aspFrom aspect?
- if (!modelGrid.GetClosestAvailable(obj, center, aspectIndexTo)) { // if cannot get any position close to the position got above
+ if (!modelGrid.GetClosestAvailable(obj, loc, aspectIndexTo)) { // if cannot get any position close to the position got above
AfxMessageBox(_T("Too Many Models! Internal Program Error!"),MB_OK | MB_ICONSTOP);
throw hresult_exception();
}
}
- obj->SetCenter(center, aspectIndexTo);
+ obj->SetLocation(loc, aspectIndexTo);
modelGrid.Set(obj, FALSE, aspectIndexTo);
}
Modified: trunk/GME/Gme/GUIObject.cpp
==============================================================================
--- trunk/GME/Gme/GUIObject.cpp Tue Sep 11 09:23:38 2012 (r2050)
+++ trunk/GME/Gme/GUIObject.cpp Tue Sep 11 09:23:58 2012 (r2051)
@@ -27,15 +27,7 @@
/////////////////////////////// Helper functions /////////////////////////////////
-void SetLocation(CRect& location, CPoint pt)
-{
- CSize s = location.Size();
- location.top = pt.y;
- location.left = pt.x;
- SetSize(location, s);
-}
-
-void SetSize(CRect& location, CSize s)
+static void SetSize(CRect& location, CSize s)
{
location.left = max(GME_GRID_SIZE, location.left / GME_GRID_SIZE * GME_GRID_SIZE);
location.top = max(GME_GRID_SIZE, location.top / GME_GRID_SIZE * GME_GRID_SIZE);
@@ -43,36 +35,12 @@
location.bottom = location.top + s.cy;
}
-void SetCenter(CRect& location, CPoint pt)
+void SetLocation(CRect& location, CPoint pt)
{
- ASSERT((pt.x % GME_GRID_SIZE) == 0);
- ASSERT((pt.y % GME_GRID_SIZE) == 0);
- CSize size = location.Size();
- int dx = size.cx / 2;
- int dy = size.cy / 2;
- while(pt.x - dx <= 0)
- pt.x += GME_GRID_SIZE;
- while(pt.y - dy <= 0)
- pt.y += GME_GRID_SIZE;
- int x1 = pt.x - dx;
- int y1 = pt.y - dy;
- location.left = x1;
- location.right = x1 + size.cx;
- location.top = y1;
- location.bottom = y1 + size.cy;
-}
-
-void SetCenterNoMga(CRect& location, CPoint pt)
-{
- CSize size = location.Size();
- int dx = size.cx / 2;
- int dy = size.cy / 2;
- int x1 = pt.x - dx;
- int y1 = pt.y - dy;
- location.left = x1;
- location.right = x1 + size.cx;
- location.top = y1;
- location.bottom = y1 + size.cy;
+ CSize s = location.Size();
+ location.top = pt.y;
+ location.left = pt.x;
+ SetSize(location, s);
}
//////////////////////////////////// CGuiAspect /////////////////////////////
@@ -1319,19 +1287,15 @@
decorStr = GME_DEFAULT_DECORATOR;
}
-void CGuiObject::SetCenter(CPoint& pt, int aspect, bool doMga)
+void CGuiObject::SetObjectLocation(CRect& rect, int aspect, bool doMga)
{
if(aspect < 0)
aspect = parentAspect;
VERIFY(aspect >= 0);
VERIFY(guiAspects[aspect] != NULL);
CRect loc = guiAspects[aspect]->GetLocation();
- if (IsReal()) {
- ::SetCenter(loc,pt);
- }
- else {
- ::SetCenterNoMga(loc, pt);
- }
+ // if (IsReal()) {
+ loc.MoveToXY(rect.left, rect.top);
guiAspects[aspect]->SetLocation(loc);
if(IsReal() && doMga)
WriteLocation(aspect);
@@ -1764,12 +1728,13 @@
while(pos) {
CGuiObject* obj = objList.GetNext(pos);
VERIFY(obj->IsVisible());
- CPoint point = obj->GetCenter() + shiftBy;
- if(!modelGrid.GetClosestAvailable(obj, point)) {
+ CRect rect = obj->GetLocation();
+ rect.MoveToXY(rect.left + shiftBy.x, rect.top + shiftBy.y);
+ if(!modelGrid.GetClosestAvailable(obj, rect)) {
AfxMessageBox(_T("Too Many Models! Internal Program Error!"),MB_OK | MB_ICONSTOP);
return;
}
- obj->SetCenter(point);
+ obj->SetLocation(rect);
modelGrid.Set(obj);
}
}
Modified: trunk/GME/Gme/GUIObject.h
==============================================================================
--- trunk/GME/Gme/GUIObject.h Tue Sep 11 09:23:38 2012 (r2050)
+++ trunk/GME/Gme/GUIObject.h Tue Sep 11 09:23:58 2012 (r2051)
@@ -14,8 +14,6 @@
extern CModelGrid modelGrid;
void SetLocation(CRect& location, CPoint pt);
-void SetSize(CRect& location, CSize s);
-void SetCenter(CRect& location, CPoint pt);
class CGuiBase : public CObject
{
@@ -247,7 +245,7 @@
const CRect& GetNameLocation(int aspect = -1) { aspect = (aspect < 0) ? parentAspect : aspect; return guiAspects[aspect]->GetNameLocation(); }
CSize GetSize(int aspect = -1) { return GetLocation(aspect).Size(); }
CPoint GetCenter() { CRect rect = GetLocation(); return rect.CenterPoint();}
- void SetCenter(CPoint& pt, int aspect = -1, bool doMga = true);
+ void SetObjectLocation(CRect& rect, int aspect = -1, bool doMga = true);
void SetSize(CSize& s, int aspect = -1, bool doMga = true);
void SetAllSizes(CSize& s, bool doMga = true);
void SetLocation(CRect& r, int aspect = -1, bool doMga = true);
Modified: trunk/GME/Gme/ModelGrid.cpp
==============================================================================
--- trunk/GME/Gme/ModelGrid.cpp Tue Sep 11 09:23:38 2012 (r2050)
+++ trunk/GME/Gme/ModelGrid.cpp Tue Sep 11 09:23:58 2012 (r2051)
@@ -85,12 +85,12 @@
view = 0;
}
-bool CModelGrid::IsAvailableG(CPoint &pt,CSize &halfSize) // centerpoint!
+bool CModelGrid::IsAvailableG(CPoint &pt,CSize &size)
{
- int startx = pt.x - halfSize.cx;
- int starty = pt.y - halfSize.cy;
- int endx = pt.x + halfSize.cx;
- int endy = pt.y + halfSize.cy;
+ int startx = pt.x;
+ int starty = pt.y;
+ int endx = pt.x + size.cx;
+ int endy = pt.y + size.cy;
// Hack to prevent labels from overlapping
starty -= 2;
if(startx < 0 || starty < 0 || endx >= GME_MAX_GRID_DIM || endy >= GME_MAX_GRID_DIM)
@@ -103,13 +103,11 @@
}
-#define FindStartEnd(pt,size,chk) \
- pt.x = (pt.x / GME_GRID_SIZE) * GME_GRID_SIZE; \
- pt.y = (pt.y / GME_GRID_SIZE) * GME_GRID_SIZE; \
- int startx = (pt.x - size.cx / 2 - 1) / GME_GRID_SIZE; \
- int starty = (pt.y - size.cy / 2 - 1) / GME_GRID_SIZE; \
- int endx = (pt.x + size.cx / 2 + GME_GRID_SIZE) / GME_GRID_SIZE; \
- int endy = (pt.y + size.cy / 2 + GME_GRID_SIZE) / GME_GRID_SIZE; \
+#define FindStartEnd(rect,chk) \
+ int startx = (rect.left / GME_GRID_SIZE); \
+ int starty = (rect.top / GME_GRID_SIZE); \
+ int endx = ((rect.right + GME_GRID_SIZE - 1) / GME_GRID_SIZE); \
+ int endy = ((rect.bottom + GME_GRID_SIZE - 1) / GME_GRID_SIZE); \
if(chk) { \
ASSERT(startx >= 0); \
ASSERT(starty >= 0); \
@@ -118,9 +116,9 @@
}
-bool CModelGrid::IsAvailable(CPoint pt,CSize size) // centerpoint!
+bool CModelGrid::IsAvailable(const CRect& rect)
{
- FindStartEnd(pt,size,0);
+ FindStartEnd(rect,0);
if(startx < 0 || starty < 0 || endx >= GME_MAX_GRID_DIM || endy >= GME_MAX_GRID_DIM)
return false;
for(int y = starty; y < endy; y++)
@@ -133,24 +131,26 @@
#define test_and_return_if_found() \
if(IsAvailableG(test,size)) { \
- pt.x = test.x * GME_GRID_SIZE; \
- pt.y = test.y * GME_GRID_SIZE; \
+ rect.MoveToXY(test.x * GME_GRID_SIZE, test.y * GME_GRID_SIZE); \
return TRUE; \
}
-bool CModelGrid::GetClosestAvailable(CSize size,CPoint &pt) // centerpoint!
+bool CModelGrid::GetClosestAvailable(CRect& rect)
{
- if(IsAvailable(pt,size)) {
- pt.x = (pt.x / GME_GRID_SIZE) * GME_GRID_SIZE;
- pt.y = (pt.y / GME_GRID_SIZE) * GME_GRID_SIZE;
+ if(IsAvailable(rect)) {
+ rect.MoveToXY((rect.left / GME_GRID_SIZE) * GME_GRID_SIZE,
+ (rect.top / GME_GRID_SIZE) * GME_GRID_SIZE);
return TRUE;
}
+
+ CPoint pt = rect.TopLeft();
pt.x /= GME_GRID_SIZE;
pt.y /= GME_GRID_SIZE;
pt.x = max(0,min(GME_MAX_GRID_DIM - 1,pt.x));
pt.y = max(0,min(GME_MAX_GRID_DIM - 1,pt.y));
- size.cx = (size.cx / 2 + GME_GRID_SIZE) / GME_GRID_SIZE;
- size.cy = (size.cy / 2 + GME_GRID_SIZE) / GME_GRID_SIZE;
+ CSize size = rect.Size();
+ size.cx = (size.cx + GME_GRID_SIZE - 1) / GME_GRID_SIZE;
+ size.cy = (size.cy + GME_GRID_SIZE - 1) / GME_GRID_SIZE;
CPoint test = pt;
for(int rad = 1; rad < GME_MAX_GRID_DIM; rad++) {
test.x = pt.x - rad;
@@ -174,9 +174,9 @@
}
-void CModelGrid::Set(CSize &size, CPoint ¢er, bool reset)
+void CModelGrid::Set(CRect& rect, bool reset)
{
- FindStartEnd(center,size,1);
+ FindStartEnd(rect,1);
for(int y = starty; y < endy; y++)
for(int x = startx; x < endx; x++)
reset ? Reset(x,y) : Set(x,y);
@@ -196,15 +196,11 @@
void CModelGrid::Set(CGuiObject *model,bool reset, int aspIdx)
{
CRect loc = model->GetLocation( aspIdx);
- CPoint pt = loc.CenterPoint();
- CSize s = loc.Size();
- Set(s,pt,reset);
+ Set(loc,reset);
if (theApp.labelAvoidance) {
loc = model->GetNameLocation( aspIdx);
- pt = loc.CenterPoint();
- s = loc.Size();
- Set(s,pt,reset);
+ Set(loc, reset);
}
}
@@ -216,11 +212,11 @@
bool CModelGrid::IsAvailable(CGuiObject *model, int aspIdx)
{
CRect rect = model->GetLocation(aspIdx);
- bool avail = modelGrid.IsAvailable(rect.CenterPoint(), rect.Size());
+ bool avail = modelGrid.IsAvailable(rect);
if (theApp.labelAvoidance) {
rect = model->GetNameLocation(aspIdx);
- avail = avail && modelGrid.IsAvailable(rect.CenterPoint(), rect.Size());
+ avail = avail && modelGrid.IsAvailable(rect);
}
return avail;
@@ -232,28 +228,9 @@
calling GetLocation or GetNameLocation with default parameter might
cause null ptr dereferencing
*/
-bool CModelGrid::GetClosestAvailable(CGuiObject *model,CPoint &pt, int aspIdx)
+bool CModelGrid::GetClosestAvailable(CGuiObject *model, CRect &rect, int aspIdx)
{
- CRect unionLoc;
- CRect loc = model->GetLocation( aspIdx);
- if (theApp.labelAvoidance) {
- CRect nameLoc = model->GetNameLocation( aspIdx);
- unionLoc.UnionRect(&loc, &nameLoc);
- }
- else {
- unionLoc = loc;
- }
-
- CSize offset = unionLoc.CenterPoint() - loc.CenterPoint();
-
- offset.cx -= offset.cx % GME_GRID_SIZE;
- offset.cy -= offset.cy % GME_GRID_SIZE;
-
- pt += offset;
-
- bool ret = GetClosestAvailable(unionLoc.Size(), pt);
-
- pt -= offset;
+ bool ret = GetClosestAvailable(rect);
return ret;
}
@@ -268,7 +245,7 @@
r.left += right;
r.top += down;
r.bottom += down;
- bool can = IsAvailable(r.CenterPoint(),r.Size());
+ bool can = IsAvailable(r);
if (theApp.labelAvoidance) {
r = model->GetNameLocation();
@@ -276,7 +253,7 @@
r.left += right;
r.top += down;
r.bottom += down;
- can = can && IsAvailable(r.CenterPoint(),r.Size());
+ can = can && IsAvailable(r);
}
return can;
Modified: trunk/GME/Gme/ModelGrid.h
==============================================================================
--- trunk/GME/Gme/ModelGrid.h Tue Sep 11 09:23:38 2012 (r2050)
+++ trunk/GME/Gme/ModelGrid.h Tue Sep 11 09:23:58 2012 (r2051)
@@ -23,7 +23,7 @@
void Reset(CGuiObject *model);
bool IsAvailable(CGuiObject *model, int aspIdx = -1);
- bool GetClosestAvailable(CGuiObject *model,CPoint &pt, int aspIdx = -1);//last param introd by zolmol
+ bool GetClosestAvailable(CGuiObject *model, CRect &pt, int aspIdx = -1);//last param introd by zolmol
bool CanNudge(CGuiObject *model,int right,int down);
@@ -33,12 +33,11 @@
void Reset(int x,int y);
bool IsAvailable(int x,int y);
- void Set(CSize &size, CPoint ¢er, bool reset = FALSE);
-
- bool IsAvailable(CPoint pt,CSize size);
+ void Set(CRect& rect, bool reset = FALSE);
+ bool IsAvailable(const CRect& rect);
bool IsAvailableG(CPoint &pt,CSize &size);
- bool GetClosestAvailable(CSize size,CPoint &pt);
+ bool GetClosestAvailable(CRect& rect);
};
#endif // whole file
\ No newline at end of file
Modified: trunk/GME/Gme/PendingObjectPosRequest.cpp
==============================================================================
--- trunk/GME/Gme/PendingObjectPosRequest.cpp Tue Sep 11 09:23:38 2012 (r2050)
+++ trunk/GME/Gme/PendingObjectPosRequest.cpp Tue Sep 11 09:23:58 2012 (r2051)
@@ -27,12 +27,6 @@
void CPendingObjectPosRequest::Execute(CGMEView *view)
{
- // DEBUG
- // CString tmp;
- // tmp.Format("Object: %s, position: %d:%d, apsect: %d", object->name, (int)position.x, (int)position.y, (int)aspect);
- // AfxMessageBox(tmp);
- // return;
-
// TRACE("\tXV: Pending request execute:");
VERIFY(view->inTransaction);
if (!object)
@@ -42,7 +36,6 @@
if(aspect < 0)
aspect = object->GetParentAspect();
VERIFY(aspect >= 0);
- ::SetCenter(location, position);
// TRACE(" object: %s, mgaptr: %p, location: %d-%d\n", object->name, object->mgaFco, (int)location.TopLeft().x, (int)location.TopLeft().y);
try {
@@ -57,7 +50,7 @@
CComPtr<IMgaMetaAspect> mAspect;
COMTHROW(mBase.QueryInterface(&mAspect));
(object->mgaFco)->get_Part(mAspect,&part);
- COMTHROW(part->SetGmeAttrs(0,location.TopLeft().x,location.TopLeft().y));
+ COMTHROW(part->SetGmeAttrs(0, location.left, location.top));
// TRACE(" \t\tEXECUTED\n");
}
catch(hresult_exception &) {
Modified: trunk/GME/Gme/PendingObjectPosRequest.h
==============================================================================
--- trunk/GME/Gme/PendingObjectPosRequest.h Tue Sep 11 09:23:38 2012 (r2050)
+++ trunk/GME/Gme/PendingObjectPosRequest.h Tue Sep 11 09:23:58 2012 (r2051)
@@ -15,14 +15,13 @@
{
public:
void Execute(CGMEView *view);
- CPendingObjectPosRequest(CGuiObject *obj, CPoint pos, CRect loc, int asp) : object(obj), position(pos), location(loc), aspect(asp){}
+ CPendingObjectPosRequest(CGuiObject *obj, CRect loc, int asp) : object(obj), location(loc), aspect(asp){}
virtual ~CPendingObjectPosRequest();
CGuiObject * object;
protected:
int aspect;
- CPoint position;
CRect location;
};
More information about the gme-commit
mailing list