COPASI API  4.16.103
Public Slots | Signals | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
CQLayoutThread Class Reference

#include <CQLayoutThread.h>

Inheritance diagram for CQLayoutThread:
Inheritance graph
[legend]
Collaboration diagram for CQLayoutThread:
Collaboration graph
[legend]

Public Slots

void terminateLayout ()
 

Signals

void layoutFinished ()
 
void layoutStateChanged (QSharedPointer< CLayoutState > newState)
 
void layoutUpdated ()
 

Public Member Functions

 CQLayoutThread (QWidget *parent)
 
void createSpringLayout (CLayout *layout, int numIntervals=1000, int updateWait=100)
 
void finalize ()
 
QDockWidget * getParameterWindow ()
 
bool pause ()
 
void randomizeLayout (CLayout *layout)
 
void resume ()
 
void stopLayout ()
 
virtual ~CQLayoutThread ()
 

Protected Member Functions

virtual void run ()
 

Protected Attributes

int mNumIterations
 
bool mPause
 
QWaitCondition mPauseCond
 
CCopasiSpringLayoutmpCurrent
 
CLayoutmpCurrentLayout
 
CQSpringLayoutParameterWindowmpParameterWindow
 
bool mStopLayout
 
QMutex mSync
 
int mUpdateWait
 

Detailed Description

Definition at line 25 of file CQLayoutThread.h.

Constructor & Destructor Documentation

CQLayoutThread::CQLayoutThread ( QWidget *  parent)

Definition at line 20 of file CQLayoutThread.cpp.

References CopasiUI3Window::getMainWindow(), mpParameterWindow, and terminateLayout().

21  : QThread(parent)
22  , mpParameterWindow(NULL)
23  , mpCurrentLayout(NULL)
24  , mNumIterations(1000)
25  , mUpdateWait(100)
26  , mStopLayout(false)
27  , mPause(false)
28  , mpCurrent(NULL)
29 {
30  qRegisterMetaType<QSharedPointer<CLayoutState> >();
31  mpParameterWindow = new CQSpringLayoutParameterWindow("Layout Parameters", parent);
32  connect(CopasiUI3Window::getMainWindow(), SIGNAL(signalQuit()), this, SLOT(terminateLayout()), Qt::DirectConnection);
33 }
CLayout * mpCurrentLayout
static CopasiUI3Window * getMainWindow()
CCopasiSpringLayout * mpCurrent
CQSpringLayoutParameterWindow * mpParameterWindow
CQLayoutThread::~CQLayoutThread ( )
virtual

Definition at line 70 of file CQLayoutThread.cpp.

References mpCurrent, mpParameterWindow, and pdelete.

71 {
74 }
#define pdelete(p)
Definition: copasi.h:215
CCopasiSpringLayout * mpCurrent
CQSpringLayoutParameterWindow * mpParameterWindow

Member Function Documentation

void CQLayoutThread::createSpringLayout ( CLayout layout,
int  numIntervals = 1000,
int  updateWait = 100 
)

Run the layout algorithm on the given layout

Definition at line 88 of file CQLayoutThread.cpp.

References mNumIterations, mpCurrentLayout, and mUpdateWait.

Referenced by CQNewMainWindow::createSpringLayout(), and CQAnimationWindow::slotAutoLayout().

89 {
90  mpCurrentLayout = layout;
91  mNumIterations = numIntervals;
92  mUpdateWait = updateWait;
93  start();
94 }
CLayout * mpCurrentLayout
void CQLayoutThread::finalize ( void  )

Definition at line 96 of file CQLayoutThread.cpp.

References CCopasiSpringLayout::finalizeState(), and mpCurrent.

Referenced by run().

97 {
98  if (mpCurrent == NULL) return;
99 
101 }
CCopasiSpringLayout * mpCurrent
QDockWidget * CQLayoutThread::getParameterWindow ( )

Definition at line 65 of file CQLayoutThread.cpp.

References mpParameterWindow.

Referenced by CQNewMainWindow::CQNewMainWindow(), and CQAnimationWindow::init().

66 {
67  return mpParameterWindow;
68 }
CQSpringLayoutParameterWindow * mpParameterWindow
void CQLayoutThread::layoutFinished ( )
signal

Referenced by run().

void CQLayoutThread::layoutStateChanged ( QSharedPointer< CLayoutState newState)
signal

Referenced by randomizeLayout(), and run().

void CQLayoutThread::layoutUpdated ( )
signal

Referenced by randomizeLayout(), and run().

bool CQLayoutThread::pause ( )

Definition at line 53 of file CQLayoutThread.cpp.

References mPause, and mSync.

54 {
55  if (mSync.tryLock(30))
56  {
57  mPause = true;
58  mSync.unlock();
59  return true;
60  }
61 
62  return false;
63 }
void CQLayoutThread::randomizeLayout ( CLayout layout)

Definition at line 76 of file CQLayoutThread.cpp.

References CQSpringLayoutParameterWindow::getLayoutParameters(), layoutStateChanged(), layoutUpdated(), mpParameterWindow, and CCopasiSpringLayout::randomize().

Referenced by CQNewMainWindow::randomizeLayout(), and CQAnimationWindow::slotRandomizeLayout().

77 {
78  if (layout == NULL || mpParameterWindow == NULL)
79  return;
80 
82  l.randomize();
83 
84  emit layoutStateChanged(QSharedPointer<CLayoutState>(new CLayoutState(layout)));
85  emit layoutUpdated();
86 }
void layoutStateChanged(QSharedPointer< CLayoutState > newState)
CCopasiSpringLayout::Parameters & getLayoutParameters()
CQSpringLayoutParameterWindow * mpParameterWindow
void layoutUpdated()
void CQLayoutThread::resume ( )

Definition at line 45 of file CQLayoutThread.cpp.

References mPause, mPauseCond, and mSync.

46 {
47  mSync.lock();
48  mPause = false;
49  mSync.unlock();
50  mPauseCond.wakeAll();
51 }
QWaitCondition mPauseCond
void CQLayoutThread::run ( )
protectedvirtual

Definition at line 109 of file CQLayoutThread.cpp.

References CCopasiSpringLayout::createVariables(), finalize(), CQSpringLayoutParameterWindow::getLayoutParameters(), layoutFinished(), layoutStateChanged(), layoutUpdated(), mNumIterations, mPause, mPauseCond, mpCurrent, mpCurrentLayout, mpParameterWindow, mStopLayout, mSync, mUpdateWait, and CLayoutEngine::step().

110 {
111  if (mpCurrentLayout == NULL)
112  return;
113 
114  mStopLayout = false;
115 
116  if (mpCurrent != NULL)
117  {
118  delete mpCurrent;
119  mpCurrent = NULL;
120  }
121 
122  // create the spring layout
125 
126  CLayoutEngine le(mpCurrent, false);
127  int i = 0;
128  qint64 tick, last = 0;
129  double pot, oldPot = -1.0;
130 
131  for (; (i < mNumIterations) && (mStopLayout) == false; ++i)
132  {
133  mSync.lock();
134 
135  if (mPause)
136  mPauseCond.wait(&mSync);
137 
138  //test again, in case we should stop after the pause
139  if (mStopLayout)
140  {
141  mSync.unlock();
142  break;
143  }
144 
145  pot = le.step();
146 
147  // no more working on the layout, release lock
148  mSync.unlock();
149 
150  if (pot == 0.0 || fabs((pot - oldPot) / pot) < 1e-9)
151  {
152  break;
153  }
154  else
155  {
156  oldPot = pot;
157  }
158 
159  tick = QDateTime::currentMSecsSinceEpoch();
160 
161  if (mUpdateWait != 0 && (tick - last > mUpdateWait))
162  {
163  last = tick;
164 
165  // calculate new curves and emit state
166  finalize();
167 
168  emit layoutStateChanged(QSharedPointer<CLayoutState>(new CLayoutState(mpCurrentLayout)));
169  emit layoutUpdated();
170  }
171  }
172 
173  // calculate new curves and emit state
174  finalize();
175 
176  emit layoutStateChanged(QSharedPointer<CLayoutState>(new CLayoutState(mpCurrentLayout)));
177  emit layoutUpdated();
178 
179  emit layoutFinished();
180 }
void layoutStateChanged(QSharedPointer< CLayoutState > newState)
CCopasiSpringLayout::Parameters & getLayoutParameters()
CLayout * mpCurrentLayout
void layoutFinished()
CCopasiSpringLayout * mpCurrent
CQSpringLayoutParameterWindow * mpParameterWindow
void layoutUpdated()
QWaitCondition mPauseCond
void CQLayoutThread::stopLayout ( )
void CQLayoutThread::terminateLayout ( )
slot

Definition at line 35 of file CQLayoutThread.cpp.

References mPauseCond, mStopLayout, and mSync.

Referenced by CQLayoutThread(), CQAnimationWindow::~CQAnimationWindow(), and CQNewMainWindow::~CQNewMainWindow().

36 {
37  mSync.lock();
38  mStopLayout = true;
39  mPauseCond.wakeAll();
40  mSync.unlock();
41 
42  wait();
43 }
QWaitCondition mPauseCond

Member Data Documentation

int CQLayoutThread::mNumIterations
protected

Number of Iterations the layout algorithm will run

Definition at line 73 of file CQLayoutThread.h.

Referenced by createSpringLayout(), and run().

bool CQLayoutThread::mPause
protected

Definition at line 88 of file CQLayoutThread.h.

Referenced by pause(), resume(), and run().

QWaitCondition CQLayoutThread::mPauseCond
protected

Definition at line 87 of file CQLayoutThread.h.

Referenced by resume(), run(), stopLayout(), and terminateLayout().

CCopasiSpringLayout* CQLayoutThread::mpCurrent
protected

Definition at line 89 of file CQLayoutThread.h.

Referenced by finalize(), run(), and ~CQLayoutThread().

CLayout* CQLayoutThread::mpCurrentLayout
protected

The current layout

Definition at line 68 of file CQLayoutThread.h.

Referenced by createSpringLayout(), and run().

CQSpringLayoutParameterWindow* CQLayoutThread::mpParameterWindow
protected

The parameter window

Definition at line 63 of file CQLayoutThread.h.

Referenced by CQLayoutThread(), getParameterWindow(), randomizeLayout(), run(), and ~CQLayoutThread().

bool CQLayoutThread::mStopLayout
protected

boolean indicating whether the layout algorithm should stop

Definition at line 83 of file CQLayoutThread.h.

Referenced by run(), stopLayout(), and terminateLayout().

QMutex CQLayoutThread::mSync
protected

Definition at line 86 of file CQLayoutThread.h.

Referenced by pause(), resume(), run(), and terminateLayout().

int CQLayoutThread::mUpdateWait
protected

Number of msecs to wait between updates, use 0 to disable updates

Definition at line 78 of file CQLayoutThread.h.

Referenced by createSpringLayout(), and run().


The documentation for this class was generated from the following files: