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

#include <CQLayoutScene.h>

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

Public Slots

void recreate ()
 

Signals

void recreateNeeded ()
 

Public Member Functions

 CQLayoutScene (CLayout *layout, CCopasiDataModel *model=NULL, CLRenderInformationBase *renderInformation=NULL)
 
const CLayoutgetCurrentLayout () const
 
CLayoutgetCurrentLayout ()
 
const CLRenderInformationBasegetCurrentRenderInfo () const
 
QGraphicsItem * getItemFor (const std::string &cn)
 
const CLRenderResolvergetResolver () const
 
void saveToFile (const std::string &fileName, const std::string &fileType="pdf")
 
void setLayout (CLayout *layout, CCopasiDataModel *model=NULL, CLRenderInformationBase *renderInformation=NULL)
 
void setRenderInformation (CCopasiDataModel *model, CLRenderInformationBase *renderInformation)
 
void setResolver (CLRenderResolver *resolver)
 
void updatePosition (const QString &key, const QPointF &newPos)
 
virtual ~CQLayoutScene ()
 

Protected Member Functions

void initializeResolver (CCopasiDataModel *model, CLRenderInformationBase *renderInformation)
 

Private Member Functions

void addGlyph (const CLGraphicalObject *go)
 
void fillFromLayout (const CLayout *layout)
 

Private Attributes

std::map< std::string,
QGraphicsItem * > 
mItems
 
CLayoutmpLayout
 
CLRenderInformationBasempRender
 
QSharedPointer< CLRenderResolvermpResolver
 

Detailed Description

Definition at line 22 of file CQLayoutScene.h.

Constructor & Destructor Documentation

CQLayoutScene::CQLayoutScene ( CLayout layout,
CCopasiDataModel model = NULL,
CLRenderInformationBase renderInformation = NULL 
)

Definition at line 37 of file CQLayoutScene.cpp.

References initializeResolver(), recreate(), and recreateNeeded().

38  : QGraphicsScene()
39  , mpLayout(layout)
40  , mpRender(renderInformation)
41  , mpResolver(NULL)
42 {
43  initializeResolver(model, renderInformation);
44  connect(this, SIGNAL(recreateNeeded()), this, SLOT(recreate()), Qt::QueuedConnection);
45 }
QSharedPointer< CLRenderResolver > mpResolver
Definition: CQLayoutScene.h:50
CLRenderInformationBase * mpRender
Definition: CQLayoutScene.h:49
CLayout * mpLayout
Definition: CQLayoutScene.h:48
void initializeResolver(CCopasiDataModel *model, CLRenderInformationBase *renderInformation)
void recreateNeeded()
CQLayoutScene::~CQLayoutScene ( )
virtual

Definition at line 137 of file CQLayoutScene.cpp.

138 {
139 }

Member Function Documentation

void CQLayoutScene::addGlyph ( const CLGraphicalObject go)
private

Definition at line 147 of file CQLayoutScene.cpp.

References CCopasiVector< T >::begin(), COPASI_OBJECT_CN, CCopasiVector< T >::end(), CCopasiObject::getCN(), CLGlyphWithCurve::getCurve(), CLGeneralGlyph::getListOfSubglyphs(), CLGraphicalObject::getModelObject(), CLCurve::getNumCurveSegments(), mItems, and mpResolver.

Referenced by fillFromLayout().

148 {
149  if (go == NULL) return;
150 
151  const CLGlyphWithCurve* curveGlyph = dynamic_cast<const CLGlyphWithCurve*>(go);
152  const CLReactionGlyph* reaction = dynamic_cast<const CLReactionGlyph*>(go);
153  const CLTextGlyph* text = dynamic_cast<const CLTextGlyph*>(go);
154  const CLGeneralGlyph* general = dynamic_cast<const CLGeneralGlyph*>(go);
155  QGraphicsItem *item = NULL;
156 
157  if (curveGlyph != NULL)
158  {
159  if (curveGlyph->getCurve().getNumCurveSegments() > 0 || reaction != NULL || general != NULL)
160  item = new CQConnectionGraphicsItem(curveGlyph,
161  mpResolver == NULL ? NULL : mpResolver.data());
162  }
163  else if (text != NULL)
164  {
165  item = new CQLabelGraphicsItem(text, mpResolver == NULL ? NULL : mpResolver.data());
166  }
167  else
168  {
169  item = new CQStyledGraphicsItem(go, mpResolver == NULL ? NULL : mpResolver.data());
170  }
171 
172  if (item != NULL)
173  {
174  CCopasiObject* obj = go->getModelObject();
175 
176  if (obj != NULL && text == NULL)
177  {
178  item->setData(COPASI_OBJECT_CN, QString(obj->getCN().c_str()));
179  mItems[obj->getCN()] = item;
180  }
181 
182  addItem(item);
183  }
184 
185  if (general != NULL)
186  {
187  const CCopasiVector<CLGraphicalObject> & subGlyphs = general->getListOfSubglyphs();
189 
190  while (it != subGlyphs.end())
191  {
192  addGlyph(*it);
193  ++it;
194  }
195  }
196 }
std::map< std::string, QGraphicsItem * > mItems
Definition: CQLayoutScene.h:52
QSharedPointer< CLRenderResolver > mpResolver
Definition: CQLayoutScene.h:50
virtual CCopasiObjectName getCN() const
iterator begin()
const CCopasiVector< CLGraphicalObject > & getListOfSubglyphs() const
iterator end()
CCopasiObject * getModelObject() const
void addGlyph(const CLGraphicalObject *go)
#define COPASI_OBJECT_CN
const CLCurve & getCurve() const
size_t getNumCurveSegments() const
Definition: CLCurve.h:168
void CQLayoutScene::fillFromLayout ( const CLayout layout)
private

Definition at line 203 of file CQLayoutScene.cpp.

References addGlyph(), CCopasiVector< T >::begin(), CCopasiVector< T >::end(), CLRenderInformationBase::getBackgroundColor(), CLayout::getListOfCompartmentGlyphs(), CLayout::getListOfGeneralGlyphs(), CLayout::getListOfMetaboliteGlyphs(), CLayout::getListOfReactionGlyphs(), CLayout::getListOfTextGlyphs(), mItems, mpRender, mpResolver, and CQRenderConverter::setBackground().

Referenced by recreate().

204 {
205  if (layout == NULL) return;
206 
207  clear();
208  mItems.clear();
209 
210  if (mpRender != NULL && mpResolver != NULL)
211  {
213  }
214 
216 
218 
219  while (itComp != comps.end())
220  {
221  addGlyph(*itComp);
222  ++itComp;
223  }
224 
225  const CCopasiVector<CLReactionGlyph> & reactions = layout->getListOfReactionGlyphs();
226 
227  CCopasiVector<CLReactionGlyph>::const_iterator itReactions = reactions.begin();
228 
229  while (itReactions != reactions.end())
230  {
231  addGlyph(*itReactions);
232  ++itReactions;
233  }
234 
235  const CCopasiVector<CLMetabGlyph> & species = layout->getListOfMetaboliteGlyphs();
236 
238 
239  while (itSpecies != species.end())
240  {
241  addGlyph(*itSpecies);
242  ++itSpecies;
243  }
244 
245  const CCopasiVector<CLTextGlyph> & texts = layout->getListOfTextGlyphs();
246 
248 
249  while (itTexts != texts.end())
250  {
251  addGlyph(*itTexts);
252  ++itTexts;
253  }
254 
255  const CCopasiVector<CLGeneralGlyph> & list = layout->getListOfGeneralGlyphs();
256 
258 
259  while (itList != list.end())
260  {
261  addGlyph(*itList);
262  ++itList;
263  }
264 }
std::map< std::string, QGraphicsItem * > mItems
Definition: CQLayoutScene.h:52
QSharedPointer< CLRenderResolver > mpResolver
Definition: CQLayoutScene.h:50
const CCopasiVector< CLTextGlyph > & getListOfTextGlyphs() const
Definition: CLayout.h:120
CLRenderInformationBase * mpRender
Definition: CQLayoutScene.h:49
const std::string & getBackgroundColor() const
iterator begin()
static void setBackground(QGraphicsScene *scene, const std::string &fill, const CLRenderResolver *resolver)
const CCopasiVector< CLCompartmentGlyph > & getListOfCompartmentGlyphs() const
Definition: CLayout.h:81
iterator end()
const CCopasiVector< CLMetabGlyph > & getListOfMetaboliteGlyphs() const
Definition: CLayout.h:94
const CCopasiVector< CLGeneralGlyph > & getListOfGeneralGlyphs() const
Definition: CLayout.h:133
void addGlyph(const CLGraphicalObject *go)
const CCopasiVector< CLReactionGlyph > & getListOfReactionGlyphs() const
Definition: CLayout.h:107
const CLayout * CQLayoutScene::getCurrentLayout ( ) const
CLayout * CQLayoutScene::getCurrentLayout ( )

Definition at line 63 of file CQLayoutScene.cpp.

References mpLayout.

64 {
65  return mpLayout;
66 }
CLayout * mpLayout
Definition: CQLayoutScene.h:48
const CLRenderInformationBase * CQLayoutScene::getCurrentRenderInfo ( ) const

Definition at line 68 of file CQLayoutScene.cpp.

References mpRender.

69 {
70  return mpRender;
71 }
CLRenderInformationBase * mpRender
Definition: CQLayoutScene.h:49
QGraphicsItem * CQLayoutScene::getItemFor ( const std::string &  cn)

Definition at line 198 of file CQLayoutScene.cpp.

References mItems.

Referenced by CQEffectDescription::applyToScene(), and CQEffectDescription::removeFromScene().

199 {
200  return mItems[cn];
201 }
std::map< std::string, QGraphicsItem * > mItems
Definition: CQLayoutScene.h:52
const CLRenderResolver * CQLayoutScene::getResolver ( ) const

Definition at line 132 of file CQLayoutScene.cpp.

References mpResolver.

133 {
134  return mpResolver.data();
135 }
QSharedPointer< CLRenderResolver > mpResolver
Definition: CQLayoutScene.h:50
void CQLayoutScene::initializeResolver ( CCopasiDataModel model,
CLRenderInformationBase renderInformation 
)
protected

Definition at line 99 of file CQLayoutScene.cpp.

References getDefaultStyle(), CListOfLayouts::getListOfGlobalRenderInformationObjects(), CCopasiDataModel::getListOfLayouts(), CLayout::getListOfLocalRenderInformationObjects(), mpLayout, mpRender, mpResolver, and CCopasiVector< T >::size().

Referenced by CQLayoutScene(), and setRenderInformation().

100 {
101  if (model == NULL)
102  return;
103 
104  if (renderInformation == NULL)
105  {
110  else
112  }
113  else
114  mpRender = renderInformation;
115 
116  if (mpLayout == NULL || mpRender == NULL)
117  return;
118 
120 
121  if (local != NULL)
123  else
124  mpResolver = QSharedPointer<CLRenderResolver>(new CLRenderResolver(*dynamic_cast<CLGlobalRenderInformation*>(mpRender), model->getListOfLayouts()->getListOfGlobalRenderInformationObjects()));
125 }
QSharedPointer< CLRenderResolver > mpResolver
Definition: CQLayoutScene.h:50
CLRenderInformationBase * mpRender
Definition: CQLayoutScene.h:49
const CCopasiVector< CLLocalRenderInformation > & getListOfLocalRenderInformationObjects() const
Definition: CLayout.h:149
virtual size_t size() const
CLayout * mpLayout
Definition: CQLayoutScene.h:48
CLGlobalRenderInformation * getDefaultStyle(size_t index)
CListOfLayouts * getListOfLayouts()
const CCopasiVector< CLGlobalRenderInformation > & getListOfGlobalRenderInformationObjects() const
void CQLayoutScene::recreate ( )
slot
void CQLayoutScene::recreateNeeded ( )
signal

Referenced by CQLayoutScene(), and updatePosition().

void CQLayoutScene::saveToFile ( const std::string &  fileName,
const std::string &  fileType = "pdf" 
)

Definition at line 73 of file CQLayoutScene.cpp.

Referenced by Arguments::handleCommandLine(), and CQLayoutView::slotSaveToFile().

74 {
75  if (fileType == "pdf")
76  {
77  QPrinter printer(QPrinter::HighResolution);
78  printer.setOutputFormat(QPrinter::PdfFormat);
79  printer.setOutputFileName(fileName.c_str());
80  QPainter painter(&printer);
81  painter.setRenderHints(
82  QPainter::Antialiasing | QPainter::HighQualityAntialiasing | QPainter::SmoothPixmapTransform);
83  render(&painter, QRect(), itemsBoundingRect());
84  painter.end();
85  }
86  else
87  {
88  const int scale = 2;
89  QImage image(QSize(width()*scale, height()*scale), QImage::Format_ARGB32);
90  QPainter painter(&image);
91  painter.setRenderHints(
92  QPainter::Antialiasing | QPainter::HighQualityAntialiasing | QPainter::SmoothPixmapTransform);
93  render(&painter, image.rect(), itemsBoundingRect());
94  painter.end();
95  image.save(fileName.c_str(), fileType.c_str());
96  }
97 }
void CQLayoutScene::setLayout ( CLayout layout,
CCopasiDataModel model = NULL,
CLRenderInformationBase renderInformation = NULL 
)

Definition at line 47 of file CQLayoutScene.cpp.

References mpLayout, and setRenderInformation().

Referenced by CQLayoutView::slotLayoutChanged().

48 {
49  mpLayout = layout;
50  setRenderInformation(model, renderInformation);
51 }
CLayout * mpLayout
Definition: CQLayoutScene.h:48
void setRenderInformation(CCopasiDataModel *model, CLRenderInformationBase *renderInformation)
void CQLayoutScene::setRenderInformation ( CCopasiDataModel model,
CLRenderInformationBase renderInformation 
)

Definition at line 53 of file CQLayoutScene.cpp.

References initializeResolver().

Referenced by setLayout(), and CQLayoutView::slotRenderInformationChanged().

54 {
55  initializeResolver(model, renderInformation);
56 }
void initializeResolver(CCopasiDataModel *model, CLRenderInformationBase *renderInformation)
void CQLayoutScene::setResolver ( CLRenderResolver resolver)

Definition at line 127 of file CQLayoutScene.cpp.

References mpResolver.

128 {
129  mpResolver = QSharedPointer<CLRenderResolver>(resolver);
130 }
QSharedPointer< CLRenderResolver > mpResolver
Definition: CQLayoutScene.h:50
void CQLayoutScene::updatePosition ( const QString &  key,
const QPointF &  newPos 
)

Definition at line 335 of file CQLayoutScene.cpp.

References CCopasiSpringLayout::finalizeState(), CKeyFactory::get(), CCopasiRootContainer::getKeyFactory(), moveObject(), mpLayout, and recreateNeeded().

Referenced by CQStyledGraphicsItem::mouseReleaseEvent(), and CQConnectionGraphicsItem::mouseReleaseEvent().

336 {
338 
339  if (kf == NULL) return;
340 
341  CLGraphicalObject* obj = dynamic_cast<CLGraphicalObject*>(kf->get(key.toStdString()));
342 
343  if (obj == NULL) return;
344 
345  CLPoint delta(newPos.x(), newPos.y());
346  moveObject(obj, delta, mpLayout);
347 
348  // restore lines
351  l.finalizeState();
352 
353  emit recreateNeeded();
354 }
CCopasiObject * get(const std::string &key)
CLayout * mpLayout
Definition: CQLayoutScene.h:48
Definition: CLBase.h:54
void recreateNeeded()
static CKeyFactory * getKeyFactory()
void moveObject(CLGraphicalObject *obj, const CLPoint &delta, CLayout *layout)

Member Data Documentation

std::map< std::string, QGraphicsItem*> CQLayoutScene::mItems
private

Definition at line 52 of file CQLayoutScene.h.

Referenced by addGlyph(), fillFromLayout(), and getItemFor().

CLayout* CQLayoutScene::mpLayout
private
CLRenderInformationBase* CQLayoutScene::mpRender
private

Definition at line 49 of file CQLayoutScene.h.

Referenced by fillFromLayout(), getCurrentRenderInfo(), and initializeResolver().

QSharedPointer<CLRenderResolver> CQLayoutScene::mpResolver
private

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