[commit] r1263 - trunk/Tools/AutoLayout
GMESRC Repository Notifications
gme-commit at list.isis.vanderbilt.edu
Tue Apr 12 13:34:19 CDT 2011
Author: ksmyth
Date: Tue Apr 12 13:34:17 2011
New Revision: 1263
Log:
Set locations to multiples of GME_GRID_SIZE. Add Use Current Result button. Layout unconnected FCOs in rows instead of 1 column
Modified:
trunk/Tools/AutoLayout/Component.rc
trunk/Tools/AutoLayout/DlgAutoLayout.cpp
trunk/Tools/AutoLayout/DlgAutoLayout.h
trunk/Tools/AutoLayout/GMEGraph.cpp
trunk/Tools/AutoLayout/Graph.h
trunk/Tools/AutoLayout/LayoutOptimization.cpp
trunk/Tools/AutoLayout/LayoutOptimization.h
trunk/Tools/AutoLayout/RawComponent.cpp
trunk/Tools/AutoLayout/resource.h
Modified: trunk/Tools/AutoLayout/Component.rc
==============================================================================
--- trunk/Tools/AutoLayout/Component.rc Mon Apr 11 16:09:56 2011 (r1262)
+++ trunk/Tools/AutoLayout/Component.rc Tue Apr 12 13:34:17 2011 (r1263)
@@ -13,13 +13,11 @@
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
-// English (U.S.) resources
+// English (United States) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
-#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
-#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
@@ -102,7 +100,7 @@
IDD_DIALOG_AUTOLAYOUT DIALOGEX 0, 0, 630, 466
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "GME AutoLayout Component"
-FONT 8, "MS Sans Serif", 0, 0, 0x0
+FONT 8, "Microsoft Sans Serif", 0, 0, 0x0
BEGIN
LTEXT "Aspects to optimize",IDC_STATIC,503,18,62,8
LISTBOX IDC_LIST_ASPECTS,503,30,109,119,LBS_NOINTEGRALHEIGHT | LBS_EXTENDEDSEL | WS_VSCROLL | WS_TABSTOP
@@ -114,6 +112,7 @@
CONTROL "Progress2",IDC_PROGRESS_ASPECT,"msctls_progress32",WS_BORDER,503,202,109,11
CONTROL "Start from scratch",IDC_CHECK_STARTFROMSCRATCH,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,503,161,71,10
PUSHBUTTON "Abort",IDC_BUTTON_ABORT,503,242,109,14
+ PUSHBUTTON "Use Current Results",IDC_BUTTON_CURRENT_RESULTS,503,263,109,14
END
@@ -123,7 +122,7 @@
//
#ifdef APSTUDIO_INVOKED
-GUIDELINES DESIGNINFO
+GUIDELINES DESIGNINFO
BEGIN
IDD_DIALOG_AUTOLAYOUT, DIALOG
BEGIN
@@ -144,12 +143,12 @@
// String Table
//
-STRINGTABLE
+STRINGTABLE
BEGIN
IDS_PROJNAME "Component"
END
-#endif // English (U.S.) resources
+#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////
Modified: trunk/Tools/AutoLayout/DlgAutoLayout.cpp
==============================================================================
--- trunk/Tools/AutoLayout/DlgAutoLayout.cpp Mon Apr 11 16:09:56 2011 (r1262)
+++ trunk/Tools/AutoLayout/DlgAutoLayout.cpp Tue Apr 12 13:34:17 2011 (r1263)
@@ -23,6 +23,7 @@
//}}AFX_DATA_INIT
m_currentSolution = NULL;
m_bAbortionRequested = false;
+ m_bCurrentResults = false;
}
CDlgAutoLayout::~CDlgAutoLayout()
@@ -38,7 +39,7 @@
COMTHROW( m_metaModel->get_Aspects( PutOut(m_metaAspects) ) );
}
-bool CDlgAutoLayout::update( int percentage, LayoutSolution * sol, double score )
+LayoutOptimizerListener::ContinueAbortOrCurrent CDlgAutoLayout::update( int percentage, LayoutSolution * sol, double score )
{
m_score = score;
m_currentSolution = sol;
@@ -67,12 +68,8 @@
}
}
- return !IsAbortionRequested();
-}
-
-bool CDlgAutoLayout::IsAbortionRequested(void) const
-{
- return m_bAbortionRequested;
+ return (m_bAbortionRequested ? LayoutOptimizerListener::ABORT :
+ (m_bCurrentResults ? LayoutOptimizerListener::CURRENT : LayoutOptimizerListener::CONTINUE));
}
void CDlgAutoLayout::DoDataExchange(CDataExchange* pDX)
@@ -86,6 +83,7 @@
DDX_Check(pDX, IDC_CHECK_STARTFROMSCRATCH, m_startFromScratch);
DDX_Control(pDX, IDC_BUTTON_START, m_startButton);
DDX_Control(pDX, IDC_BUTTON_ABORT, m_abortButton);
+ DDX_Control(pDX, IDC_BUTTON_CURRENT_RESULTS, m_currentResultsButton);
//}}AFX_DATA_MAP
}
@@ -94,6 +92,7 @@
ON_WM_DRAWITEM()
ON_BN_CLICKED(IDC_BUTTON_START, OnButtonStart)
ON_BN_CLICKED(IDC_BUTTON_ABORT, OnButtonAbort)
+ ON_BN_CLICKED(IDC_BUTTON_CURRENT_RESULTS, OnButtonCurrentResults)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
@@ -129,6 +128,7 @@
m_progressAspect.ShowWindow( SW_HIDE );
m_abortButton.EnableWindow(FALSE);
+ m_currentResultsButton.EnableWindow(FALSE);
return TRUE;
}
@@ -214,6 +214,7 @@
checkBoxWnd->EnableWindow(FALSE);
m_startButton.EnableWindow(FALSE);
m_abortButton.EnableWindow(TRUE);
+ m_currentResultsButton.EnableWindow(TRUE);
m_progressOptimization.ShowWindow( SW_SHOW );
m_progressAspect.ShowWindow( SW_SHOW );
@@ -226,7 +227,7 @@
if( selNum == 0 )
return;
- for( int i=0; i<m_listAspects.GetCount() && !IsAbortionRequested(); ++i )
+ for( int i=0; i<m_listAspects.GetCount() && !m_bAbortionRequested; ++i )
{
if( m_listAspects.GetSel(i) > 0 )
{
@@ -241,7 +242,7 @@
LayoutOptimizer optimizer( &graph );
m_updateTime = 0;
optimizer.optimize( this, m_startFromScratch>0 );
- if ( !IsAbortionRequested() )
+ if ( !m_bAbortionRequested )
{
m_currentSolution = NULL;
m_graph.Invalidate(FALSE);
@@ -281,15 +282,20 @@
CDialog::OnCancel();
}
- if (IsAbortionRequested())
+ if (m_bAbortionRequested)
CDialog::OnCancel();
else
CDialog::OnOK();
}
+void CDlgAutoLayout::OnButtonCurrentResults()
+{
+ m_bCurrentResults = true;
+}
+
void CDlgAutoLayout::OnButtonAbort()
{
- int nRet = ::AfxMessageBox("Are you sure you want to abort the auto-layouting procedure?", MB_YESNO | MB_ICONWARNING);
+ int nRet = IDYES; // ::AfxMessageBox("Are you sure you want to abort the auto-layouting procedure?", MB_YESNO | MB_ICONWARNING);
if (nRet == IDYES)
m_bAbortionRequested = true;
else
Modified: trunk/Tools/AutoLayout/DlgAutoLayout.h
==============================================================================
--- trunk/Tools/AutoLayout/DlgAutoLayout.h Mon Apr 11 16:09:56 2011 (r1262)
+++ trunk/Tools/AutoLayout/DlgAutoLayout.h Tue Apr 12 13:34:17 2011 (r1263)
@@ -27,9 +27,7 @@
void initialzie( IMgaProject * project, IMgaModel* model );
- virtual bool update( int percentage, LayoutSolution * sol, double score );
-
- bool IsAbortionRequested(void) const;
+ virtual LayoutOptimizerListener::ContinueAbortOrCurrent update( int percentage, LayoutSolution * sol, double score );
// Dialog Data
//{{AFX_DATA(CDlgAutoLayout)
@@ -41,6 +39,7 @@
BOOL m_startFromScratch;
CButton m_startButton;
CButton m_abortButton;
+ CButton m_currentResultsButton;
//}}AFX_DATA
@@ -72,6 +71,7 @@
int m_updateTime;
bool m_bAbortionRequested;
+ bool m_bCurrentResults;
// Generated message map functions
//{{AFX_MSG(CDlgAutoLayout)
@@ -79,6 +79,7 @@
virtual BOOL OnInitDialog();
afx_msg void OnButtonStart();
afx_msg void OnButtonAbort();
+ afx_msg void OnButtonCurrentResults();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
Modified: trunk/Tools/AutoLayout/GMEGraph.cpp
==============================================================================
--- trunk/Tools/AutoLayout/GMEGraph.cpp Mon Apr 11 16:09:56 2011 (r1262)
+++ trunk/Tools/AutoLayout/GMEGraph.cpp Tue Apr 12 13:34:17 2011 (r1263)
@@ -58,6 +58,7 @@
COMTHROW( fco->get_ObjType(&type) );
COMTHROW( part->GetGmeAttrs(&icon,&x,&y) );
+ // FIXME what about SET
if( type == OBJTYPE_ATOM || type == OBJTYPE_MODEL || type == OBJTYPE_REFERENCE )
{
CComBSTR decoratorProgID;
@@ -82,6 +83,9 @@
COMTHROW(decorator->Initialize(project, metaPart, fco));
COMTHROW( decorator->GetPreferredSize( &sx, &sy ) );
+ // round sx and sy up to nearest GME_GRID_SIZE multiple
+ sx = (sx + GME_GRID_SIZE - 1) / GME_GRID_SIZE * GME_GRID_SIZE;
+ sy = (sy + GME_GRID_SIZE - 1) / GME_GRID_SIZE * GME_GRID_SIZE;
COMTHROW( decorator->SetLocation( x, y, x+sx, y+sy ) );
Node * node = new Node( sx, sy );
Modified: trunk/Tools/AutoLayout/Graph.h
==============================================================================
--- trunk/Tools/AutoLayout/Graph.h Mon Apr 11 16:09:56 2011 (r1262)
+++ trunk/Tools/AutoLayout/Graph.h Tue Apr 12 13:34:17 2011 (r1263)
@@ -3,6 +3,8 @@
#include <vector>
+#define GME_GRID_SIZE 7 // from GME GMEStd.h
+
struct Node;
struct Edge;
Modified: trunk/Tools/AutoLayout/LayoutOptimization.cpp
==============================================================================
--- trunk/Tools/AutoLayout/LayoutOptimization.cpp Mon Apr 11 16:09:56 2011 (r1262)
+++ trunk/Tools/AutoLayout/LayoutOptimization.cpp Tue Apr 12 13:34:17 2011 (r1263)
@@ -8,6 +8,9 @@
using GAOptimizer::IGenotype;
using GAOptimizer::IProblem;
+#ifdef max
+#undef max
+#endif
LayoutOptimizer::LayoutOptimizer( Graph * graph )
{
@@ -19,9 +22,10 @@
int i,j;
int x = 0;
int m = 100;
- bool noAbort = true;
+ int maxy = 0;
+ LayoutOptimizerListener::ContinueAbortOrCurrent status = LayoutOptimizerListener::ContinueAbortOrCurrent::CONTINUE;
- for( i=0; i<m_graph->getNumberOfSubGraphs() && noAbort; ++i )
+ for( i=0; i<m_graph->getNumberOfSubGraphs() && status == LayoutOptimizerListener::CONTINUE; ++i )
{
LayoutOptProblem problem( m_graph, i, startFromScratch );
GAOptimizer::Optimizer optimizer;
@@ -29,15 +33,15 @@
optimizer.init( &problem, 500, 20 );
LayoutSolution * best;
- for( j=0; j<m && noAbort; ++j )
+ for( j=0; j<m && status == LayoutOptimizerListener::CONTINUE; ++j )
{
optimizer.step(800);
best = (LayoutSolution*)optimizer.getBest();
if( listener != NULL )
- noAbort = listener->update( (int)(100 * (i*m+j) / double(m_graph->getNumberOfSubGraphs() * m)), best, optimizer.getMaxFitness() );
+ status = listener->update( (int)(100 * (i*m+j) / double(m_graph->getNumberOfSubGraphs() * m)), best, optimizer.getMaxFitness() );
}
- if ( noAbort )
+ if ( status != LayoutOptimizerListener::ABORT )
{
// get best, place it, write back positions to m_graph
best->crop();
@@ -47,21 +51,32 @@
{
best->m_nodes[j].m_node->m_x = best->m_nodes[j].m_x;
best->m_nodes[j].m_node->m_y = best->m_nodes[j].m_y;
+ maxy = std::max(maxy, best->m_nodes[j].m_y + m_graph->m_nodes[j]->m_sy);
}
}
}
- if ( noAbort )
+ if ( status != LayoutOptimizerListener::ABORT )
{
- // place not connected nodes
- int y = YMARGIN;
+ // place not connected nodes in rows
+ int y = YMARGIN + maxy;
+ int max_y_size = 0;
+ x = XMARGIN;
for( i=0; i<m_graph->m_nodes.size(); ++i )
{
if( !(m_graph->m_nodes[i]->m_connectedToOthers) )
{
+ if ((m_graph->m_nodes[i]->m_sx + XMARGIN + x > 600)
+ && (x > 100))
+ {
+ x = XMARGIN;
+ y += max_y_size + YMARGIN;
+ max_y_size = 0;
+ }
m_graph->m_nodes[i]->m_x = x;
m_graph->m_nodes[i]->m_y = y;
- y += m_graph->m_nodes[i]->m_sy + 2 * YMARGIN;
+ x += m_graph->m_nodes[i]->m_sx + XMARGIN;
+ max_y_size = std::max(max_y_size, m_graph->m_nodes[i]->m_sy);
}
}
}
Modified: trunk/Tools/AutoLayout/LayoutOptimization.h
==============================================================================
--- trunk/Tools/AutoLayout/LayoutOptimization.h Mon Apr 11 16:09:56 2011 (r1262)
+++ trunk/Tools/AutoLayout/LayoutOptimization.h Tue Apr 12 13:34:17 2011 (r1263)
@@ -7,8 +7,8 @@
#include "GAOptimizer.h"
#include "Graph.h"
-#define XMARGIN 50
-#define YMARGIN 20
+#define XMARGIN (GME_GRID_SIZE * 5)
+#define YMARGIN (GME_GRID_SIZE * 3)
typedef std::vector<int> IntVec;
typedef std::set<int> IntSet;
@@ -18,7 +18,12 @@
class LayoutOptimizerListener
{
public:
- virtual bool update( int percentage, LayoutSolution * sol, double score ) = 0;
+ enum ContinueAbortOrCurrent {
+ CONTINUE,
+ ABORT,
+ CURRENT,
+ };
+ virtual ContinueAbortOrCurrent update( int percentage, LayoutSolution * sol, double score ) = 0;
};
class LayoutOptimizer
Modified: trunk/Tools/AutoLayout/RawComponent.cpp
==============================================================================
--- trunk/Tools/AutoLayout/RawComponent.cpp Mon Apr 11 16:09:56 2011 (r1262)
+++ trunk/Tools/AutoLayout/RawComponent.cpp Tue Apr 12 13:34:17 2011 (r1263)
@@ -64,10 +64,12 @@
CDlgAutoLayout dlg;
dlg.initialzie( project, (IMgaModel*)currentobj );
- if( dlg.DoModal() != IDOK )
- throw 0;
-
- COMTHROW( project->CommitTransaction() );
+ INT_PTR dlgResult = dlg.DoModal();
+ if (dlgResult == IDOK ) {
+ COMTHROW( project->CommitTransaction() );
+ } else {
+ COMTHROW( project->AbortTransaction() );
+ }
}
catch(...)
{
Modified: trunk/Tools/AutoLayout/resource.h
==============================================================================
--- trunk/Tools/AutoLayout/resource.h Mon Apr 11 16:09:56 2011 (r1262)
+++ trunk/Tools/AutoLayout/resource.h Tue Apr 12 13:34:17 2011 (r1263)
@@ -11,6 +11,7 @@
#define IDC_PROGRESS_ASPECT 209
#define IDC_CHECK_STARTFROMSCRATCH 210
#define IDC_BUTTON_ABORT 211
+#define IDC_BUTTON_CURRENT_RESULTS 212
// Next default values for new objects
//
@@ -18,7 +19,7 @@
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 203
#define _APS_NEXT_COMMAND_VALUE 32768
-#define _APS_NEXT_CONTROL_VALUE 212
+#define _APS_NEXT_CONTROL_VALUE 213
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
More information about the gme-commit
mailing list