[commit] r1447 - trunk/Tools/AutoLayout
GMESRC Repository Notifications
gme-commit at list.isis.vanderbilt.edu
Wed Jul 27 15:51:24 CDT 2011
Author: ksmyth
Date: Wed Jul 27 15:51:24 2011
New Revision: 1447
Log:
Support automated invocation. Fix decorator leak due to no Destroy()
Modified:
trunk/Tools/AutoLayout/DlgAutoLayout.cpp
trunk/Tools/AutoLayout/DlgAutoLayout.h
trunk/Tools/AutoLayout/GMEGraph.cpp
trunk/Tools/AutoLayout/RawComponent.cpp
Modified: trunk/Tools/AutoLayout/DlgAutoLayout.cpp
==============================================================================
--- trunk/Tools/AutoLayout/DlgAutoLayout.cpp Wed Jul 27 10:40:51 2011 (r1446)
+++ trunk/Tools/AutoLayout/DlgAutoLayout.cpp Wed Jul 27 15:51:24 2011 (r1447)
@@ -30,7 +30,7 @@
{
}
-void CDlgAutoLayout::initialzie( IMgaProject * project, IMgaModel* model )
+void CDlgAutoLayout::initialize( IMgaProject * project, IMgaModel* model )
{
m_project = project;
m_model = model;
@@ -204,6 +204,54 @@
}
}
+void CDlgAutoLayout::OptimizeAllAspects() {
+ long count;
+ COMTHROW(m_metaAspects->get_Count(&count));
+ for (int i = 1; i <= count; i++)
+ {
+ CComObjPtr<IMgaMetaAspect> aspect;
+ COMTHROW(m_metaAspects->get_Item(i, &aspect.p));
+ Optimize(aspect);
+ }
+}
+
+void CDlgAutoLayout::Optimize(CComObjPtr<IMgaMetaAspect>& aspect) {
+ // optimize aspect layout
+ GMEGraph graph( m_project, m_model, aspect );
+ LayoutOptimizer optimizer( &graph );
+ m_updateTime = 0;
+ optimizer.optimize( (this->GetSafeHwnd() ? this : NULL), m_startFromScratch>0 );
+ if ( !m_bAbortionRequested )
+ {
+ m_currentSolution = NULL;
+ if (m_graph.GetSafeHwnd())
+ m_graph.Invalidate(FALSE);
+
+ // write back results to gme
+ CComObjPtr<IMgaParts> parts;
+ long n;
+ COMTHROW( m_model->get_AspectParts(aspect, 0, PutOut(parts)) );
+ COMTHROW( parts->get_Count(&n) );
+
+ for( int i=0; i<n; ++i )
+ {
+ CComObjPtr<IMgaPart> part;
+ CComObjPtr<IMgaFCO> fco;
+
+ COMTHROW( parts->get_Item(i+1, PutOut(part)) );
+ COMTHROW( part->get_FCO(PutOut(fco)) );
+
+ for( unsigned int j=0; j<graph.m_nodes.size(); ++j )
+ {
+ if( fco == graph.m_nodes[j]->m_fco )
+ {
+ COMTHROW( part->SetGmeAttrs(0, graph.m_nodes[j]->m_x, graph.m_nodes[j]->m_y) );
+ }
+ }
+ }
+ }
+}
+
void CDlgAutoLayout::OnButtonStart()
{
try
@@ -237,39 +285,6 @@
CComObjPtr<IMgaMetaAspect> aspect;
COMTHROW( m_metaAspects->get_Item( i+1, PutOut(aspect) ) );
- // oprimize aspect layout
- GMEGraph graph( m_project, m_model, aspect );
- LayoutOptimizer optimizer( &graph );
- m_updateTime = 0;
- optimizer.optimize( this, m_startFromScratch>0 );
- if ( !m_bAbortionRequested )
- {
- m_currentSolution = NULL;
- m_graph.Invalidate(FALSE);
-
- // write back results to gme
- CComObjPtr<IMgaParts> parts;
- long n;
- COMTHROW( m_model->get_AspectParts(aspect, 0, PutOut(parts)) );
- COMTHROW( parts->get_Count(&n) );
-
- for( int i=0; i<n; ++i )
- {
- CComObjPtr<IMgaPart> part;
- CComObjPtr<IMgaFCO> fco;
-
- COMTHROW( parts->get_Item(i+1, PutOut(part)) );
- COMTHROW( part->get_FCO(PutOut(fco)) );
-
- for( unsigned int j=0; j<graph.m_nodes.size(); ++j )
- {
- if( fco == graph.m_nodes[j]->m_fco )
- {
- COMTHROW( part->SetGmeAttrs(0, graph.m_nodes[j]->m_x, graph.m_nodes[j]->m_y) );
- }
- }
- }
- }
}
}
Modified: trunk/Tools/AutoLayout/DlgAutoLayout.h
==============================================================================
--- trunk/Tools/AutoLayout/DlgAutoLayout.h Wed Jul 27 10:40:51 2011 (r1446)
+++ trunk/Tools/AutoLayout/DlgAutoLayout.h Wed Jul 27 15:51:24 2011 (r1447)
@@ -25,7 +25,7 @@
virtual ~CDlgAutoLayout();
- void initialzie( IMgaProject * project, IMgaModel* model );
+ void initialize( IMgaProject * project, IMgaModel* model );
virtual LayoutOptimizerListener::ContinueAbortOrCurrent update( int percentage, LayoutSolution * sol, double score );
@@ -50,6 +50,9 @@
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
+public:
+ void OptimizeAllAspects();
+ void Optimize(CComObjPtr<IMgaMetaAspect>& aspect);
// Implementation
protected:
void drawSolution( CDC * dc, LayoutSolution * sol );
Modified: trunk/Tools/AutoLayout/GMEGraph.cpp
==============================================================================
--- trunk/Tools/AutoLayout/GMEGraph.cpp Wed Jul 27 10:40:51 2011 (r1446)
+++ trunk/Tools/AutoLayout/GMEGraph.cpp Wed Jul 27 15:51:24 2011 (r1447)
@@ -132,6 +132,9 @@
}
catch (hresult_exception&) {
}
+ if (decorator) {
+ decorator->Destroy();
+ }
}
}
}
Modified: trunk/Tools/AutoLayout/RawComponent.cpp
==============================================================================
--- trunk/Tools/AutoLayout/RawComponent.cpp Wed Jul 27 10:40:51 2011 (r1446)
+++ trunk/Tools/AutoLayout/RawComponent.cpp Wed Jul 27 15:51:24 2011 (r1447)
@@ -6,6 +6,9 @@
///////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
+#include <Gdiplus.h>
+#pragma comment(lib, "gdiplus.lib")
+
//#include "ComHelp.h"
//#include "GMECOM.h"
#include "ComponentLib.h"
@@ -63,12 +66,34 @@
}
CDlgAutoLayout dlg;
- dlg.initialzie( project, (IMgaModel*)currentobj );
- INT_PTR dlgResult = dlg.DoModal();
- if (dlgResult == IDOK ) {
- COMTHROW( project->CommitTransaction() );
+ dlg.initialize( project, (IMgaModel*)currentobj );
+ if (param == 128)
+ {
+ Gdiplus::GdiplusStartupInput gdiplusStartupInput;
+ Gdiplus::GdiplusStartupOutput gdiplusStartupOutput;
+ ULONG_PTR gdiplusToken;
+ ULONG_PTR gdiplusHookToken;
+
+ // Initializing GDI+
+ // See "Special CWinApp Services" MSDN topic http://msdn.microsoft.com/en-us/library/001tckck.aspx
+ gdiplusStartupInput.SuppressBackgroundThread = TRUE;
+ VERIFY(Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, &gdiplusStartupOutput) == Gdiplus::Ok);
+ gdiplusStartupOutput.NotificationHook(&gdiplusHookToken);
+
+ dlg.OptimizeAllAspects();
+ // n.b. need to unload decorators before shutting down GDI+
+ CoFreeUnusedLibraries();
+ // Closing GDI+
+ gdiplusStartupOutput.NotificationUnhook(gdiplusHookToken);
+ Gdiplus::GdiplusShutdown(gdiplusToken);
+ COMTHROW( project->CommitTransaction() );
} else {
- COMTHROW( project->AbortTransaction() );
+ INT_PTR dlgResult = dlg.DoModal();
+ if (dlgResult == IDOK ) {
+ COMTHROW( project->CommitTransaction() );
+ } else {
+ COMTHROW( project->AbortTransaction() );
+ }
}
}
catch(...)
More information about the gme-commit
mailing list