• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kstars

  • sources
  • kde-4.12
  • kdeedu
  • kstars
  • kstars
  • skycomponents
starblocklist.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  starblocklist.cpp - K Desktop Planetarium
3  -------------------
4  begin : Mon 9 Jun 2008
5  copyright : (C) 2008 by Akarsh Simha
6  email : akarshsimha@gmail.com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "starblocklist.h"
19 #include "binfilehelper.h"
20 #include "starblockfactory.h"
21 #include "skyobjects/stardata.h"
22 #include "skyobjects/deepstardata.h"
23 #include "starcomponent.h"
24 
25 #include <kde_file.h>
26 
27 StarBlockList::StarBlockList( Trixel tr, DeepStarComponent *parent ) {
28  trixel = tr;
29  nStars = 0;
30  readOffset = 0;
31  faintMag = -5.0;
32  nBlocks = 0;
33  this->parent = parent;
34  staticStars = parent->hasStaticStars();
35 }
36 
37 StarBlockList::~StarBlockList() {
38  // NOTE: Rest of the StarBlocks are taken care of by StarBlockFactory
39  if( staticStars && blocks[ 0 ] )
40  delete blocks[0];
41 }
42 
43 int StarBlockList::releaseBlock( StarBlock *block ) {
44 
45  if( block != blocks[ nBlocks - 1 ] )
46  kDebug() << "ERROR: Trying to release a block which is not the last block! Trixel = " << trixel << endl;
47 
48  else if( blocks.size() > 0 ) {
49 
50  blocks.removeLast();
51  nBlocks--;
52  nStars -= block->getStarCount();
53 
54  readOffset -= parent->getStarReader()->guessRecordSize() * block->getStarCount();
55  if( nBlocks <= 0 )
56  faintMag = -5.0;
57  else
58  faintMag = blocks[nBlocks - 1]->faintMag;
59 
60  return 1;
61  }
62 
63  return 0;
64 }
65 
66 bool StarBlockList::fillToMag( float maglim ) {
67  // TODO: Remove staticity of BinFileHelper
68  BinFileHelper *dSReader;
69  StarBlockFactory *SBFactory;
70  starData stardata;
71  deepStarData deepstardata;
72  FILE *dataFile;
73 
74  dSReader = parent->getStarReader();
75  dataFile = dSReader->getFileHandle();
76  SBFactory = StarBlockFactory::Instance();
77 
78  if( staticStars )
79  return false;
80 
81  if( faintMag >= maglim )
82  return true;
83 
84  if( !dataFile ) {
85  kDebug() << "dataFile not opened!";
86  return false;
87  }
88 
89  Trixel trixelId = trixel; //( ( trixel < 256 ) ? ( trixel + 256 ) : ( trixel - 256 ) ); // Trixel ID on datafile is assigned differently
90 
91  if( readOffset <= 0 )
92  readOffset = dSReader->getOffset( trixelId );
93 
94  Q_ASSERT( nBlocks == blocks.size() );
95 
96  BinFileHelper::unsigned_KDE_fseek( dataFile, readOffset, SEEK_SET );
97 
98  /*
99  kDebug() << "Reading trixel" << trixel << ", id on disk =" << trixelId << ", currently nStars =" << nStars
100  << ", record count =" << dSReader->getRecordCount( trixelId ) << ", first block = " << blocks[0]->getStarCount()
101  << "to maglim =" << maglim << "with current faintMag =" << faintMag << endl;
102  */
103 
104  while( maglim >= faintMag && nStars < dSReader->getRecordCount( trixelId ) ) {
105  if( nBlocks == 0 || blocks[nBlocks - 1]->isFull() ) {
106  StarBlock *newBlock;
107  newBlock = SBFactory->getBlock();
108  if( !newBlock ) {
109  kWarning() << "ERROR: Could not get a new block from StarBlockFactory::getBlock() in trixel "
110  << trixel << ", while trying to create block #" << nBlocks + 1 << endl;
111  return false;
112  }
113  blocks.append( newBlock );
114  blocks[nBlocks]->parent = this;
115  if( nBlocks == 0 )
116  SBFactory->markFirst( blocks[0] );
117  else if( !SBFactory->markNext( blocks[nBlocks - 1], blocks[nBlocks] ) )
118  kWarning() << "ERROR: markNext() failed on block #" << nBlocks + 1 << "in trixel" << trixel;
119 
120  ++nBlocks;
121  }
122  // TODO: Make this more general
123  if( dSReader->guessRecordSize() == 32 ) {
124  fread( &stardata, sizeof( starData ), 1, dataFile );
125  if( dSReader->getByteSwap() )
126  DeepStarComponent::byteSwap( &stardata );
127  readOffset += sizeof( starData );
128  blocks[nBlocks - 1]->addStar(stardata);
129  }
130  else {
131  fread( &deepstardata, sizeof( deepStarData ), 1, dataFile );
132  if( dSReader->getByteSwap() )
133  DeepStarComponent::byteSwap( &deepstardata );
134  readOffset += sizeof( deepStarData );
135  blocks[nBlocks - 1]->addStar(deepstardata);
136  }
137 
138  /*
139  if( faintMag > -5.0 && fabs(faintMag - blocks[nBlocks - 1]->getFaintMag()) > 0.2 ) {
140  kDebug() << "Encountered a jump from mag" << faintMag << "to mag"
141  << blocks[nBlocks - 1]->getFaintMag() << "in trixel" << trixel;
142  }
143  */
144  faintMag = blocks[nBlocks - 1]->getFaintMag();
145  nStars++;
146  }
147 
148  return ( ( maglim < faintMag ) ? true : false );
149 }
150 
151 void StarBlockList::setStaticBlock( StarBlock *block ) {
152  if( !block )
153  return;
154  if ( nBlocks == 0 ) {
155  blocks.append( block );
156  }
157  else
158  blocks[0] = block;
159 
160  blocks[0]->parent = this;
161  faintMag = blocks[0]->faintMag;
162  nBlocks = 1;
163  staticStars = true;
164 }
deepStarData
Structure that holds star data for really faint stars.
Definition: deepstardata.h:28
StarBlockList::StarBlockList
StarBlockList(Trixel trixel)
Constructor.
starData
Structure that holds star data.
Definition: stardata.h:28
DeepStarComponent
Stores and manages unnamed stars, most of which are dynamically loaded into memory.
Definition: deepstarcomponent.h:49
StarBlock
Holds a block of stars and various peripheral variables to mark its place in data structures...
Definition: starblock.h:38
StarBlockFactory::markFirst
bool markFirst(StarBlock *block)
Mark a StarBlock as most recently used and sync its drawID with the current drawID.
Definition: starblockfactory.cpp:79
starcomponent.h
deepstardata.h
StarBlockList::~StarBlockList
~StarBlockList()
Destructor.
Definition: starblocklist.cpp:37
BinFileHelper::getFileHandle
FILE * getFileHandle()
Get the file handle corresponding to the currently open file.
Definition: binfilehelper.h:132
stardata.h
BinFileHelper
This class provides utility functions to handle binary data files in the format prescribed by KStars...
Definition: binfilehelper.h:52
StarBlockFactory
A factory that creates StarBlocks and recycles them in an LRU Cache.
Definition: starblockfactory.h:32
BinFileHelper::guessRecordSize
int guessRecordSize()
Return a guessed record size.
Definition: binfilehelper.h:167
starblockfactory.h
BinFileHelper::getByteSwap
bool getByteSwap()
Should we do byte swapping?
Definition: binfilehelper.h:159
Trixel
unsigned int Trixel
Definition: htmesh/typedef.h:4
StarBlockList::setStaticBlock
void setStaticBlock(StarBlock *block)
Sets the first StarBlock in the list to point to the given StarBlock.
Definition: starblocklist.cpp:151
binfilehelper.h
BinFileHelper::unsigned_KDE_fseek
static int unsigned_KDE_fseek(FILE *stream, quint32 offset, int whence)
Wrapper around fseek for large offsets.
Definition: binfilehelper.cpp:259
StarBlock::getStarCount
int getStarCount()
Return the number of stars currently filled in this StarBlock.
Definition: starblock.h:110
StarBlockFactory::Instance
static StarBlockFactory * Instance()
Definition: starblockfactory.cpp:29
StarBlockFactory::markNext
bool markNext(StarBlock *after, StarBlock *block)
Rank a given StarBlock after another given StarBlock in the LRU list and sync its drawID with the cur...
Definition: starblockfactory.cpp:117
StarBlockList::releaseBlock
int releaseBlock(StarBlock *block)
Drops the StarBlock with the given pointer from the list.
Definition: starblocklist.cpp:43
DeepStarComponent::hasStaticStars
bool hasStaticStars()
Definition: deepstarcomponent.h:72
starblocklist.h
StarBlockList::fillToMag
bool fillToMag(float maglim)
Ensures that the list is loaded with stars to given magnitude limit.
Definition: starblocklist.cpp:66
BinFileHelper::getOffset
long getOffset(int id)
Returns the offset in the file corresponding to the given index ID.
Definition: binfilehelper.h:139
DeepStarComponent::byteSwap
static void byteSwap(deepStarData *stardata)
Definition: deepstarcomponent.cpp:453
StarBlockFactory::getBlock
StarBlock * getBlock()
Return a StarBlock available for use.
Definition: starblockfactory.cpp:49
StarBlockList::block
StarBlock * block(unsigned int i)
Returns the i-th block in this StarBlockList.
Definition: starblocklist.h:88
DeepStarComponent::getStarReader
BinFileHelper * getStarReader()
Definition: deepstarcomponent.h:92
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:21 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kstars

Skip menu "kstars"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal