[idlescreen commit] r198 - trunk/src/PlasmaGenerator/src

0 views
Skip to first unread message

codesite...@google.com

unread,
Mar 7, 2009, 9:44:18 PM3/7/09
to dev-idl...@googlegroups.com
Author: jeff.backus
Date: Sat Mar 7 18:41:07 2009
New Revision: 198

Added:
trunk/src/PlasmaGenerator/src/PlasmaGenerator.h
trunk/src/PlasmaGenerator/src/PlasmaGeneratorMain.cpp
trunk/src/PlasmaGenerator/src/PlasmaGeneratorProfile.cpp
trunk/src/PlasmaGenerator/src/PlasmaGeneratorProfile.h
Modified:
trunk/src/PlasmaGenerator/src/ConfigManager.cpp
trunk/src/PlasmaGenerator/src/ConfigManager.h
trunk/src/PlasmaGenerator/src/PlasmaGenerator.cpp
trunk/src/PlasmaGenerator/src/PlasmaGeneratorDialog.cpp
trunk/src/PlasmaGenerator/src/PlasmaGeneratorDialog.h
trunk/src/PlasmaGenerator/src/project_specific_extern_defs.h

Log:
Command-line mode works perfectly now. Need to start on the GUI.


Modified: trunk/src/PlasmaGenerator/src/ConfigManager.cpp
==============================================================================
--- trunk/src/PlasmaGenerator/src/ConfigManager.cpp (original)
+++ trunk/src/PlasmaGenerator/src/ConfigManager.cpp Sat Mar 7 18:41:07 2009
@@ -22,9 +22,9 @@
*
*/

-// debug
#include <iostream>
using namespace std;
+// debug
//#include <QMessageBox>
//#include "lens_engine/SphericalLensProfile.h"

@@ -39,6 +39,7 @@
#include "utility/misc_funcs.h"
#include "core/win_misc_funcs.h"
#include "project_specific_extern_defs.h"
+#include "PlasmaGeneratorProfile.h"

#include "ConfigManager.h"

@@ -62,12 +63,10 @@
QCoreApplication::addLibraryPath(libPath);
*/

-
_bGPLAccepted = false;
}

ConfigManager::~ConfigManager() {
-
//clean out hashes
deleteAllSettings();
}
@@ -127,14 +126,20 @@
void ConfigManager::deleteAllSettings() {

//clean out hashes
- keys = _paletteHash.keys();
+ QList<QString> keys = _paletteHash.keys();
for(int i=0; i<keys.size();i++) {
IndexedPaletteProfile* tmpPtr = _paletteHash.take(keys.at(i));
delete tmpPtr;
tmpPtr = NULL;
}

- //clean out lists
+ keys = _profiles.keys();
+ for(int i=0; i<keys.size();i++) {
+ PlasmaGeneratorProfile* tmpPtr = _profiles.take(keys.at(i));
+ delete tmpPtr;
+ tmpPtr = NULL;
+ }
+
_bGPLAccepted = false;
}

@@ -158,7 +163,7 @@
QDomElement root = doc.documentElement();

//load palette profiles
- tempNode =
doc.firstChildElement().firstChildElement(IndexedPaletteProfile::getXMLTagName());
+ QDomElement tempNode =
doc.firstChildElement().firstChildElement(IndexedPaletteProfile::getXMLTagName());
while(!tempNode.isNull()) {
IndexedPaletteProfile* tempProfile =
IndexedPaletteProfile::load(tempNode);
//if non-NULL, add it to the hash of palette profiles
@@ -168,6 +173,20 @@
tempNode =
tempNode.nextSiblingElement(IndexedPaletteProfile::getXMLTagName());
}

+ //load plasma generator profiles
+ tempNode = doc.firstChildElement().
+ firstChildElement(PlasmaGeneratorProfile::getXMLTagName());
+ while(!tempNode.isNull()) {
+ PlasmaGeneratorProfile* tempProfile =
+ PlasmaGeneratorProfile::load(tempNode);
+ //if non-NULL, add it to the hash of palette profiles
+ if(tempProfile != NULL) {
+ _profiles.insert(tempProfile->getName(), tempProfile);
+ }
+ tempNode = tempNode.
+ nextSiblingElement(PlasmaGeneratorProfile::getXMLTagName());
+ }
+
//load misc info
if(bLoadMiscInfo) {
loadMiscInfo(root);
@@ -197,11 +216,17 @@
doc.appendChild(root);

//store palette profiles..
- keys = _paletteHash.keys();
+ QList<QString> keys = _paletteHash.keys();
for(int i=0; i<keys.size();i++) {
root.appendChild(_paletteHash.value(keys.at(i))->save(&doc));
}

+ //store plasma generator profiles..
+ keys = _profiles.keys();
+ for(int i=0; i<keys.size();i++) {
+ root.appendChild(_profiles.value(keys.at(i))->save(&doc));
+ }
+
if(bSaveMiscInfo) {
saveMiscInfo(&doc, &root);
}
@@ -227,6 +252,11 @@
_bGPLAccepted = stringToBool(param);
}

+ tempElem = node.firstChildElement("default_profile");
+ if(!tempElem.isNull()) {
+ _defaultProfile = tempElem.text();
+ }
+
tempElem = node.firstChildElement("default_texture_width");
if(!tempElem.isNull()) {
_defWidth = tempElem.text().toInt();
@@ -250,6 +280,12 @@
tempElem.appendChild(tempNode);
root->appendChild(tempElem);

+ // default profile
+ tempNode = doc->createTextNode(_defaultProfile);
+ tempElem = doc->createElement("default_profile");
+ tempElem.appendChild(tempNode);
+ root->appendChild(tempElem);
+
// default texture width
tempStr.setNum(_defWidth);
tempNode = doc->createTextNode(tempStr);
@@ -313,9 +349,9 @@
// first, alert all background profiles that a palette is being
// removed if bUpdateProfiles is true.
if(bUpdateProfiles) {
- QList<QString> keys = _backgroundHash.keys();
+ QList<QString> keys = _profiles.keys();
for(int i=0; i<keys.size();i++) {
- _backgroundHash.value(keys.at(i))->paletteRemoved(name);
+ _profiles.value(keys.at(i))->paletteRemoved(name);
}
}

@@ -365,9 +401,9 @@

// alert all background profiles that a palette is being
// replaced
- QList<QString> keys = _backgroundHash.keys();
+ QList<QString> keys = _profiles.keys();
for(int i=0; i<keys.size();i++) {
- _backgroundHash.value(keys.at(i))->paletteNameChanged(oldPaletteName,
+ _profiles.value(keys.at(i))->paletteNameChanged(oldPaletteName,
newPalName);
}
} else {
@@ -402,5 +438,158 @@
*/
QString ConfigManager::getProgName() {
return getAppConfigName();
+}
+
+/**
+ * Gets the default profile name.
+ */
+QString ConfigManager::getDefaultProfile() {
+ if(!doesProfileExist(_defaultProfile)) {
+ QList<QString> keys = _profiles.keys();
+ if(!keys.empty()) {
+ _defaultProfile = keys.at(0);
+ } else {
+ _defaultProfile = "";
+ }
+ }
+ return _defaultProfile;
+}
+
+/**
+ * Sets the default profile name.
+ */
+void ConfigManager::setDefaultProfile(QString profileName) {
+ _defaultProfile = profileName;
+}
+
+/**
+ * Gets the list of all PlasmaGeneratorProfiles.
+ */
+QStringList ConfigManager::getAvailableProfiles() {
+ return _profiles.keys();
+}
+
+/**
+ * Removes the selected profile. Returns whether successful.
+ */
+bool ConfigManager::removeProfile(QString name) {
+ return (_profiles.remove(name) > 0);
+}
+
+/**
+ * Adds a new profile to the hash.
+ */
+void ConfigManager::addProfile(PlasmaGeneratorProfile& profile) {
+ //check for preexisting profile name.
+ if(!doesProfileExist(profile.getName())) {
+ //if not, create a new profile off of the heap to add to the hash.
+ PlasmaGeneratorProfile* newProfile = new PlasmaGeneratorProfile();
+ *newProfile = profile;
+ _profiles.insert(profile.getName(), newProfile);
+ }
+}
+
+/**
+ * Retrieves a copy of the specified profile.
+ */
+PlasmaGeneratorProfile& ConfigManager::getProfile(QString name) {
+ PlasmaGeneratorProfile* retVal = _profiles.value(name);
+
+ if(retVal != NULL)
+ return *retVal;
+
+ //if the specified profile isn't in the hash, return a new one.
+ PlasmaGeneratorProfile newProfile;
+ return newProfile;
+}
+
+/**
+ * Replaces the profile with the specified name with the
+ * specified profile.
+ */
+bool ConfigManager::replaceProfile(QString oldProfileName,
PlasmaGeneratorProfile& newProfile) {
+ //first, check to see if the new profile name is already in the list and
that
+ //it isn't the same as the old name. If so, fail.
+ QString newProfileName = newProfile.getName();
+ if(oldProfileName != newProfileName && doesProfileExist(newProfileName))
{
+ return false;
+ }
+
+ //now check to see if the old profile name is in the list. if so,
replace, otherwise add.
+ if(doesProfileExist(oldProfileName)) {
+ removeProfile(oldProfileName);
+ addProfile(newProfile);
+ } else {
+ addProfile(newProfile);
+ }
+
+ return true;
+}
+
+/**
+ * Checks to see if a palette with the specified name is already
+ * in the hash.
+ */
+bool ConfigManager::doesProfileExist(QString name) {
+ return _profiles.contains(name);
+}
+
+/**
+ * This is an uber function for command-line mode that will
+ * generate a plasma based on the arguments provided. If any
+ * of them are empty, defaults will be used.
+ */
+bool ConfigManager::GeneratePlasmaFile(QString profileName,
+ QString outFileName,
+ bool bOverwriteOverride,
+ bool bOverwrite) {
+ // if the profile name wasn't specified, get the default.
+ if(profileName.isEmpty()) {
+ profileName = getDefaultProfile();
+ }
+
+ // if the profile doesn't exist,
+ if(!doesProfileExist(profileName)) {
+ cout<<"Profile '"<<profileName.toStdString()<<"' doesn't exist!"<<endl;
+ return false;
+ }
+
+ PlasmaGeneratorProfile profile = getProfile(profileName);
+
+ if(outFileName.isEmpty()) {
+ outFileName = profile.getFileTarget();
+ }
+
+ if(!bOverwriteOverride) {
+ bOverwrite = (profile.getOverwritePolicy()==ALWAYS);
+ }
+
+ // get the generator and generate a plasma!
+ PlasmaGenerator* plasma = profile.getGenerator(&_paletteHash);
+
+ if(plasma == NULL) {
+ cout<<"Unable to create generator!"<<endl;
+ return false;
+ }
+
+ if(!plasma->genPlasma()) {
+ cout<<"Unable to generate plasma!"<<endl;
+ delete plasma;
+ plasma = NULL;
+ return false;
+ }
+
+ if(!plasma->savePlasma(outFileName, bOverwrite)) {
+ cout<<"Unable to save plasma!"<<endl;
+ delete plasma;
+ plasma = NULL;
+ return false;
+ }
+
+ // clean up
+ delete plasma;
+ plasma = NULL;
+
+ return true;
}


Modified: trunk/src/PlasmaGenerator/src/ConfigManager.h
==============================================================================
--- trunk/src/PlasmaGenerator/src/ConfigManager.h (original)
+++ trunk/src/PlasmaGenerator/src/ConfigManager.h Sat Mar 7 18:41:07 2009
@@ -34,7 +34,6 @@
#ifdef _M_IX86
#include <windows.h>
#else
-//#include <stream.h>
#include <stdlib.h>
#endif

@@ -46,123 +45,179 @@
#include <QHash>
#include <QStringList>

-#include "globaldefs.h"
-#include "lens_engine/LensObject.h"
-#include "lens_engine/LensProfile.h"
-#include "../IndexedPalette/IndexedPalette.h"
-#include "../IndexedPalette/IndexedPaletteProfile.h"
-#include "BackgroundProfile.h"
-#include "MasterProfile.h"
+#include "2d_bgnd_w_lens/globaldefs.h"
+#include "IndexedPalette/IndexedPalette.h"
+#include "IndexedPalette/IndexedPaletteProfile.h"
+
+#include "PlasmaGeneratorProfile.h"

class ConfigManager {

-public:
- //Constructor and deconstructor
- ConfigManager();
- ~ConfigManager();
-
- void load();
- void save();
-
- bool importFromFile(QString filename, bool bLoadMiscInfo);
- bool exportToFile(QString filename, bool bSaveMiscInfo);
-
- void deleteAllSettings();
-
- //Sets defaults
- void setDefaults();
-
- //*** Begin Timer Related ***
-
- /**
- * Returns the number of milliseconds between each timer tick.
- */
- long getTimerMillis();
-
- //*** End Timer Related ***
-
- //*** Begin Screen Related ***
- int getTextureWidth();
- int getTextureHeight();
- //*** End Screen Related
-
- //*** Begin Palette Related ***
-
- /**
- * Returns a list of the names of the palettes currently
- * in the palette hash.
- */
- QStringList getPaletteNames();
-
- /**
- * Removes the palette with the specified name from the hash.
- * If bUpdateProfiles is true, it will iterate through all
- * background profiles alerting them to the removal. When
- * replacing a palette, this should be false!
- */
- bool removePalette(QString name, bool bUpdateProfiles=true);
-
- /**
- * Adds the specified palette to the hash if it isn't already
- * in the hash. Returns whether successful.
- */
- void addPalette(IndexedPaletteProfile& pal);
-
- /**
- * Checks to see if a palette with the specified name is already
- * in the hash.
- */
- bool doesPaletteExist(QString name);
-
- /**
- * Replaces the palette with the specified name with the
- * specified palette if the new name isn't already
- * in the list.
- */
- bool replacePalette(QString oldPaletteName, IndexedPaletteProfile&
newPalette);
-
- /**
- * Returns a copy of the specified palette profile. Caller should
- * check for existence first with doesPaletteExist();
- */
- IndexedPaletteProfile getPaletteProfile(const QString& name);
- //*** End Palette Related ***
-
- //*** Begin Misc ***
-
- //whether or not the GPL has been accepted
- bool getGPLAccepted();
- void setGPLAccepted(bool bAccepted);
-
- //creates a new ConfigManager object that only contains the specified
configuration.
- //it is intended for to be used in generating the preview widget.
- ConfigManager* createPreview(int width = 64, int height = 64,
LensProfile* lensProfile = NULL, BackgroundProfile* backgroundProfile =
NULL, int timerMillis = 50);
-
- /**
- * Gets the human-readable name of the program.
- */
- QString getProgName();
-
- //*** End Misc ***
-
-protected:
- QString getMainConfigFile();
- QString getMainConfigPath();
- QString getExternalDefaultConfigFile();
- QString getExternalDefaultConfigPath();
-
- void loadMiscInfo(QDomNode &node);
- void saveMiscInfo(QDomDocument* doc, QDomElement* root);
-
- // returns the string used in as the Dom root.
- QString getDomNodeQString();
+ public:
+ //Constructor and deconstructor
+ ConfigManager();
+ ~ConfigManager();
+
+ void load();
+ void save();
+
+ bool importFromFile(QString filename, bool bLoadMiscInfo);
+ bool exportToFile(QString filename, bool bSaveMiscInfo);
+
+ void deleteAllSettings();
+
+ //Sets defaults
+ void setDefaults();
+
+ //*** Begin Timer Related ***
+
+ /**
+ * Returns the number of milliseconds between each timer tick.
+ */
+ long getTimerMillis();
+
+ //*** End Timer Related ***
+
+ //*** Begin Screen Related ***
+ int getTextureWidth();
+ int getTextureHeight();
+ //*** End Screen Related
+
+ //*** Begin PlasmaGeneratorProfile Related ***
+
+ /**
+ * Gets the default profile name.
+ */
+ QString getDefaultProfile();
+
+ /**
+ * Sets the default profile name.
+ */
+ void setDefaultProfile(QString profileName);
+
+ /**
+ * Gets the list of all PlasmaGeneratorProfiles.
+ */
+ QStringList getAvailableProfiles();
+
+ /**
+ * Removes the selected profile. Returns whether successful.
+ */
+ bool removeProfile(QString name);
+
+ /**
+ * Adds a new profile to the hash.
+ */
+ void addProfile(PlasmaGeneratorProfile& profile);
+
+ /**
+ * Retrieves a copy of the specified profile.
+ */
+ PlasmaGeneratorProfile& getProfile(QString name);
+
+ /**
+ * Replaces the profile with the specified name with the
+ * specified profile.
+ */
+ bool replaceProfile(QString oldProfileName,
+ PlasmaGeneratorProfile& newProfile);
+
+ /**
+ * Checks to see if a profile with the specified name is already
+ * in the hash.
+ */
+ bool doesProfileExist(QString name);
+
+ //*** End PlasmaGeneratorProfile Related ***
+
+ //*** Begin Palette Related ***
+
+ /**
+ * Returns a list of the names of the palettes currently
+ * in the palette hash.
+ */
+ QStringList getPaletteNames();
+
+ /**
+ * Removes the palette with the specified name from the hash.
+ * If bUpdateProfiles is true, it will iterate through all
+ * background profiles alerting them to the removal. When
+ * replacing a palette, this should be false!
+ */
+ bool removePalette(QString name, bool bUpdateProfiles=true);
+
+ /**
+ * Adds the specified palette to the hash if it isn't already
+ * in the hash. Returns whether successful.
+ */
+ void addPalette(IndexedPaletteProfile& pal);
+
+ /**
+ * Checks to see if a palette with the specified name is already
+ * in the hash.
+ */
+ bool doesPaletteExist(QString name);
+
+ /**
+ * Replaces the palette with the specified name with the
+ * specified palette if the new name isn't already
+ * in the list.
+ */
+ bool replacePalette(QString oldPaletteName, IndexedPaletteProfile&
newPalette);
+
+ /**
+ * Returns a copy of the specified palette profile. Caller should
+ * check for existence first with doesPaletteExist();
+ */
+ IndexedPaletteProfile getPaletteProfile(const QString& name);
+ //*** End Palette Related ***
+
+ //*** Begin Misc ***
+
+ //whether or not the GPL has been accepted
+ bool getGPLAccepted();
+ void setGPLAccepted(bool bAccepted);
+
+ //creates a new ConfigManager object that only contains the specified
configuration.
+ //it is intended for to be used in generating the preview widget.
+ // ConfigManager* createPreview(int width = 64, int height = 64,
LensProfile* lensProfile = NULL, BackgroundProfile* backgroundProfile =
NULL, int timerMillis = 50);
+
+ /**
+ * Gets the human-readable name of the program.
+ */
+ QString getProgName();
+
+ /**
+ * This is an uber function for command-line mode that will
+ * generate a plasma based on the arguments provided. If any
+ * of them are empty, defaults will be used.
+ */
+ bool GeneratePlasmaFile(QString profileName, QString outFileName,
+ bool bOverwriteOverride, bool bOverwrite);
+
+ //*** End Misc ***
+
+ protected:
+ QString getMainConfigFile();
+ QString getMainConfigPath();
+ QString getExternalDefaultConfigFile();
+ QString getExternalDefaultConfigPath();
+
+ void loadMiscInfo(QDomNode &node);
+ void saveMiscInfo(QDomDocument* doc, QDomElement* root);
+
+ // returns the string used in as the Dom root.
+ QString getDomNodeQString();
+
+ QHash<QString, PlasmaGeneratorProfile*> _profiles;
+ QString _defaultProfile;

- QHash<QString, IndexedPaletteProfile*> _paletteHash;
+ QHash<QString, IndexedPaletteProfile*> _paletteHash;

- bool _bGPLAccepted;
+ bool _bGPLAccepted;

- int _defWidth;
- int _defHeight;
+ int _defWidth;
+ int _defHeight;
};

Modified: trunk/src/PlasmaGenerator/src/PlasmaGenerator.cpp
==============================================================================
--- trunk/src/PlasmaGenerator/src/PlasmaGenerator.cpp (original)
+++ trunk/src/PlasmaGenerator/src/PlasmaGenerator.cpp Sat Mar 7 18:41:07
2009
@@ -1,5 +1,5 @@
/**
- * Copyright (c) 2008 Jeff Backus.
+ * Copyright (c) 2009 Jeff Backus.
*
* Licensed under the GNU General Public License, Version 2.0
(the "License");
* you may not use this file except in compliance with the License.
@@ -22,48 +22,217 @@
*
*/

+// begin debug
+//#include <iostream>
+//using namespace std;
+//end debug
+
+#include <QFile>
+
+#include "PlasmaGenerator.h"
+
+/**
+ * Public constructor.
+ */
+PlasmaGenerator::PlasmaGenerator() {
+ _height = 0;
+ _width = 0;
+ _bClampColor = true;
+ _bTileHorizontal = false;
+ _bTileVertical = false;
+ _coarseness = 1.0;
+}
+
+/**
+ * Public destructor.
+ */
+PlasmaGenerator::~PlasmaGenerator() {
+ // nada
+}
+
+/**
+ * Retrieves the plasma's height.
+ */
+int PlasmaGenerator::getHeight() {
+ return _height;
+}
+
+/**
+ * Sets the plasma's height.
+ */
+void PlasmaGenerator::setHeight(int height) {
+ _height = height;
+}
+
+/**
+ * Retrieves the plasma's width.
+ */
+int PlasmaGenerator::getWidth() {
+ return _width;
+}
+
+/**
+ * Sets the plasma's width.
+ */
+void PlasmaGenerator::setWidth(int width) {
+ _width = width;
+}
+
+/**
+ * Gets the palette.
+ */
+IndexedPalette& PlasmaGenerator::getPalette() {
+ return _pal;
+}
+
+/**
+ * Sets the palette.
+ */
+void PlasmaGenerator::setPalette(IndexedPalette& pal) {
+ _pal = pal;
+}
+
+/**
+ * Gets whether to clamp the color (as opposed to wrapping). See
+ * PlasmaAlgorithm.h for more information.
+ */
+bool PlasmaGenerator::getClampColor() {
+ return _bClampColor;
+}
+
+/**
+ * Sets whether to clamp the color or not. See PlasmaAlgorithm.h for
+ * more informatin.
+ */
+void PlasmaGenerator::setClampColor(bool bClampColor) {
+ _bClampColor = bClampColor;
+}
+
+/**
+ * Gets whether to set the plasma up for horizontal tiling or not.
+ */
+bool PlasmaGenerator::getTileHorizontal() {
+ return _bTileHorizontal;
+}
+
/**
- * This is the main entry point for the PlasmaGenerator.
+ * Sets whether to set the plasma up for horizontal tiling or not.
*/
+void PlasmaGenerator::setTileHorizontal(bool bTileHorizontal) {
+ _bTileHorizontal = bTileHorizontal;
+}

-#include <QApplication>
+/**
+ * Gets whether to set the plasma up for vertical tiling or not.
+ */
+bool PlasmaGenerator::getTileVertical() {
+ return _bTileVertical;
+}

-#include "ConfigManager.h"
-#include "PlasmaGeneratorDialog.h"
+/**
+ * Sets whether to set the plasma up for vertical tiling or not.
+ */
+void PlasmaGenerator::setTileVertical(bool bTileVertical) {
+ _bTileVertical = bTileVertical;
+}

-int main(int argv, char** argc) {
+/**
+ * Gets the coarseness factor to use.
+ */
+float PlasmaGenerator::getCoarseness() {
+ return _coarseness;
+}
+
+/**
+ * Sets the coarseness factor to use.
+ */
+void PlasmaGenerator::setCoarseness(float coarseness) {
+ _coarseness = coarseness;
+}

- //start up the QApp
- QApplication app(argc, argc);
+/**
+ * Generates a new plasma. Returns true if successful.
+ */
+bool PlasmaGenerator::genPlasma() {

- //load configuration
- ConfigManager manager;
- manager.load();
+ int numColors = _pal.getWidth();

- //set up the dialog
- PlasmaGeneratorDialog* dlg = new PlasmaGeneratorDialog();
- if(dlg == NULL) {
- exit(1);
- }
+ if(_height < 1 || _width < 1 || numColors < 1 || _coarseness < 0.0) {
+ return false;
+ }
+
+ // calculate the number of steps
+ float totalNumSteps = (_height*_width /
+ PLASMAGENERATOR_NUM_ITERS_PER_CALC) + _height;
+ float currStep = 0;
+
+ // initialize the PlasmaAlgorithm, then step through each calc
+ // step, emitting a progress update each time.
+ int* field = new int[_height*_width];
+ if(field == NULL) {
+ return false;
+ }
+
+ PlasmaAlgorithm plasma;
+
+ if(!plasma.initialize(field, _width, _height, numColors, _coarseness,
+ _bClampColor, _bTileHorizontal, _bTileVertical)) {
+ return false;
+ }
+
+ while(!plasma.calc(PLASMAGENERATOR_NUM_ITERS_PER_CALC)) {
+ currStep+=1.0;
+ emit progressUpdated((int)(currStep*100.0/totalNumSteps));
+ }
+
+ // generate a new plasma then stuff into a QImage object.
+ _img = QImage(_width, _height, QImage::Format_ARGB32);
+ int buff[4];
+
+ for(int y = 0; y<_height; y++) {
+ for(int x=0; x<_width; x++) {
+ _pal.getColor(field[y*_width+x],0,&buff[0], 4);
+ QRgb color = qRgba(buff[0], buff[1], buff[2], buff[3]);
+ _img.setPixel(x, y, color);
+ }
+ currStep+=1.0;
+ emit progressUpdated((int)(currStep*100.0/totalNumSteps));
+ }
+
+ // clean up
+ delete [] field;
+ field = NULL;

- dlg->setManager(&manager);
-
- //so that ok/cancel buttons work.
- QObject::connect(dlg, SIGNAL(dialogFinished()), &app, SLOT(quit()));
+ return true;
+}

- dlg->setup();
+/**
+ * Retrieves the plasma as a QImage object.
+ */
+QImage& PlasmaGenerator::getPlasma() {
+ return _img;
+}

- //make sure that the GPL has been accepted.
- if(!manager.getGPLAccepted()) {
- dlg->showGPLDialog();
- if(!manager.getGPLAccepted()) {
- return;
- }
- }
+/**
+ * Saves the plasma to the specified path. Returns true on success.
+ */
+bool PlasmaGenerator::savePlasma(QString filename, bool bOverwrite) {
+ QString targFileName = filename;

- //make the dialog visible
- dlg->show();
+ if(!bOverwrite) {
+ int num = 1;
+ QString ext = filename.right(filename.size() -
filename.lastIndexOf("."));
+ QString prefix = filename.left(filename.lastIndexOf("."));
+
+ // check to see if a file by that name already exists. If so,
+ // then append a number increment until a file with the combined
+ // name doesn't exist.
+ while(QFile(targFileName).exists()) {
+ targFileName = prefix + QString("_")+
+ QString::number(num++) + ext;
+ }
+ }

- //run the dialog box
- app.exec();
+ // save
+ _img.save(targFileName);
}

Added: trunk/src/PlasmaGenerator/src/PlasmaGenerator.h
==============================================================================
--- (empty file)
+++ trunk/src/PlasmaGenerator/src/PlasmaGenerator.h Sat Mar 7 18:41:07 2009
@@ -0,0 +1,165 @@
+/**
+ * Copyright (c) 2009 Jeff Backus.
+ *
+ * Licensed under the GNU General Public License, Version 2.0
(the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Additionally, this code makes heavy use of the Qt libraries from
+ * Trolltech. These libraries are released under the GNU
+ * General Public License, Version 2.0, as well. Please contact
+ * Trolltech for more information.
+ *
+ * http://trolltech.com/
+ *
+ */
+
+/**
+ * This class generates a new plasma based on the dimensions and palette
+ * information provided. It can produce QImage objects of the plasma as
+ * well as save the plasma to a file.
+ */
+
+#ifndef __PLASMAGENERATOR_H__
+#define __PLASMAGENERATOR_H__
+
+#include <QObject>
+#include <QImage>
+#include <QString>
+
+#include "IndexedPalette/IndexedPalette.h"
+#include "plasma/PlasmaAlgorithm.h"
+
+#define PLASMAGENERATOR_NUM_ITERS_PER_CALC 2000
+
+class PlasmaGenerator : public QObject {
+
+ Q_OBJECT
+
+ public:
+ /**
+ * Public constructor.
+ */
+ PlasmaGenerator();
+
+ /**
+ * Public destructor.
+ */
+ ~PlasmaGenerator();
+
+ /**
+ * Retrieves the plasma's height.
+ */
+ int getHeight();
+
+ /**
+ * Sets the plasma's height.
+ */
+ void setHeight(int height);
+
+ /**
+ * Retrieves the plasma's width.
+ */
+ int getWidth();
+
+ /**
+ * Sets the plasma's width.
+ */
+ void setWidth(int width);
+
+ /**
+ * Gets the palette.
+ */
+ IndexedPalette& getPalette();
+
+ /**
+ * Sets the palette.
+ */
+ void setPalette(IndexedPalette& pal);
+
+ /**
+ * Gets whether to clamp the color (as opposed to wrapping). See
+ * PlasmaAlgorithm.h for more information.
+ */
+ bool getClampColor();
+
+ /**
+ * Sets whether to clamp the color or not. See PlasmaAlgorithm.h for
+ * more informatin.
+ */
+ void setClampColor(bool bClampColor);
+
+ /**
+ * Gets whether to set the plasma up for horizontal tiling or not.
+ */
+ bool getTileHorizontal();
+
+ /**
+ * Sets whether to set the plasma up for horizontal tiling or not.
+ */
+ void setTileHorizontal(bool bTileHorizontal);
+
+ /**
+ * Gets whether to set the plasma up for vertical tiling or not.
+ */
+ bool getTileVertical();
+
+ /**
+ * Sets whether to set the plasma up for vertical tiling or not.
+ */
+ void setTileVertical(bool bTileVertical);
+
+ /**
+ * Gets the coarseness factor to use.
+ */
+ float getCoarseness();
+
+ /**
+ * Sets the coarseness factor to use.
+ */
+ void setCoarseness(float coarseness);
+
+ /**
+ * Generates a new plasma. Returns true if successful.
+ */
+ bool genPlasma();
+
+ /**
+ * Retrieves the plasma as a QImage object.
+ */
+ QImage& getPlasma();
+
+ /**
+ * Saves the plasma to the specified path. Returns true on success.
+ */
+ bool savePlasma(QString filename, bool bOverwrite=false);
+
+ signals:
+ /**
+ * This signal is emitted every so often with an indicator as
+ * to the percentage of completed calculations.
+ */
+ void progressUpdated(int percentComplete);
+
+ private:
+ int _height;
+ int _width;
+ IndexedPalette _pal;
+ bool _bClampColor;
+ bool _bTileHorizontal;
+ bool _bTileVertical;
+ float _coarseness;
+
+ QImage _img;
+
+};
+
+#endif

Modified: trunk/src/PlasmaGenerator/src/PlasmaGeneratorDialog.cpp
==============================================================================
--- trunk/src/PlasmaGenerator/src/PlasmaGeneratorDialog.cpp (original)
+++ trunk/src/PlasmaGenerator/src/PlasmaGeneratorDialog.cpp Sat Mar 7
18:41:07 2009
@@ -39,10 +39,10 @@

#include <QString>

-#include "IndexedPaletteDialog.h"
+#include "IndexedPalette/IndexedPaletteDialog.h"
//#include "IndexedPaletteEditorRawWidget.h"
-#include "IndexedPaletteEditorTableWidget.h"
-#include "../utility/HelpDialog.h"
+#include "IndexedPalette/IndexedPaletteEditorTableWidget.h"
+#include "utility/HelpDialog.h"

IndexedPaletteDialog::IndexedPaletteDialog(IndexedPaletteProfile*
palProfile, QWidget* parent, Qt::WindowFlags f) {
QDialog(parent, f);

Modified: trunk/src/PlasmaGenerator/src/PlasmaGeneratorDialog.h
==============================================================================
--- trunk/src/PlasmaGenerator/src/PlasmaGeneratorDialog.h (original)
+++ trunk/src/PlasmaGenerator/src/PlasmaGeneratorDialog.h Sat Mar 7
18:41:07 2009
@@ -35,8 +35,8 @@
#include <QLabel>
#include <QSpinBox>

-#include "IndexedPaletteProfile.h"
-#include "IndexedPaletteEditorWidget.h"
+#include "IndexedPalette/IndexedPaletteProfile.h"
+#include "IndexedPalette/IndexedPaletteEditorWidget.h"

class PlasmaGeneratorDialog : public QDialog {


Added: trunk/src/PlasmaGenerator/src/PlasmaGeneratorMain.cpp
==============================================================================
--- (empty file)
+++ trunk/src/PlasmaGenerator/src/PlasmaGeneratorMain.cpp Sat Mar 7
18:41:07 2009
@@ -0,0 +1,176 @@
+/**
+ * Copyright (c) 2008 Jeff Backus.
+ *
+ * Licensed under the GNU General Public License, Version 2.0
(the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Additionally, this code makes heavy use of the Qt libraries from
+ * Trolltech. These libraries are released under the GNU
+ * General Public License, Version 2.0, as well. Please contact
+ * Trolltech for more information.
+ *
+ * http://trolltech.com/
+ *
+ */
+
+/**
+ * This is the main entry point for the PlasmaGenerator.
+ */
+
+#include <iostream>
+using namespace std;
+
+#include <QApplication>
+#include <QStringList>
+
+#include "ConfigManager.h"
+#include "project_specific_extern_defs.h"
+//#include "PlasmaGeneratorDialog.h"
+
+int doHelp(QString* appName, QApplication *app) {
+ cout<<getAppFullName().toStdString()<<" v. "<<
+ getAppVersion().toStdString()<<endl;
+ cout<<"Part of the IdleScreen Project"<<endl;
+ cout<<"http://sites.google.com/site/idlescreenproject/"<<endl<<endl;
+ cout<<"Usage: "<<appName->toStdString()<<" [options]"<<endl;
+ cout<<endl<<"Options:"<<endl;
+ cout<<"\t-h\t\tDisplay help and version information"<<endl;
+ cout<<"\t-c\t\tUse command-line mode."<<endl;
+ cout<<"\t-p [filename]\tUse the specified profile"<<endl;
+ cout<<"\t-o [filename]\tOutput Plasma to specified filename"<<endl;
+ cout<<"\t-n\t\tForce never overwrite target file"<<endl;
+ cout<<"\t-a\t\tForce always overwrite target file"<<endl;
+ cout<<endl<<"Note that if command-line mode isn't specified the default
is GUI mode. In"<<endl;
+ cout<<"GUI mode, all options are ignored. Also note that any
Qt-specific options will"<<endl;
+ cout<<"be passed on to Qt regardless of other options
specified."<<endl<<endl;
+ return 0;
+}
+
+int doCommandLine(QStringList* args, QApplication *app) {
+ if(app == NULL) {
+ return -1;
+ }
+
+ //load configuration
+ ConfigManager manager;
+ manager.load();
+
+ QString profileName;
+ QString outfileName;
+ bool bOverwrite = false;
+ bool bSpecifyOverwrite = false;
+
+ // process arguments
+ int i = 0;
+ while(i<args->size()) {
+ if(args->at(i).compare(QString("-o"), Qt::CaseInsensitive) == 0) {
+ // specify output file name
+ if(i+1 < args->size()) {
+ outfileName = args->at(i+1);
+ }
+ i+=2;
+ } else if(args->at(i).compare(QString("-p"), Qt::CaseInsensitive) ==
0) {
+ // specify profile name
+ if(i+1 < args->size()) {
+ profileName = args->at(i+1);
+ }
+ i+=2;
+ } else if(args->at(i).compare(QString("-n"), Qt::CaseInsensitive) ==
0) {
+ // never overwrite
+ bSpecifyOverwrite = true;
+ bOverwrite = false;
+ i++;
+ } else if(args->at(i).compare(QString("-a"), Qt::CaseInsensitive) ==
0) {
+ // always overwrite
+ bSpecifyOverwrite = true;
+ bOverwrite = true;
+ i++;
+ } else {
+ i++;
+ }
+ }
+
+ // have ConfigManager generate and save the plasma
+ if(!manager.GeneratePlasmaFile(profileName, outfileName,
bSpecifyOverwrite,
+ bOverwrite))
+ return -1;
+
+ return 0;
+}
+
+int doDialog(QStringList* args, QApplication *app) {
+ if(app == NULL) {
+ return -1;
+ }
+
+ //load configuration
+ ConfigManager manager;
+ manager.load();
+ /*
+ //set up the dialog
+ PlasmaGeneratorDialog* dlg = new PlasmaGeneratorDialog();
+ if(dlg == NULL) {
+ return -1;
+ }
+
+ dlg->setManager(&manager);
+
+ //so that ok/cancel buttons work.
+ QObject::connect(dlg, SIGNAL(dialogFinished()), app, SLOT(quit()));
+
+ dlg->setup();
+
+ //make sure that the GPL has been accepted.
+ if(!manager.getGPLAccepted()) {
+ dlg->showGPLDialog();
+ if(!manager.getGPLAccepted()) {
+ return -1;
+ }
+ }
+
+ //make the dialog visible
+ dlg->show();
+
+ //run the dialog box
+ app->exec();
+ */
+ return 0;
+}
+
+int main(int argv, char** argc) {
+
+ QString appName = argc[0];
+
+ //start up the QApp
+ QApplication app(argv, argc);
+
+ bool bComMode = false;
+ QStringList argList;
+ // convert arguments to QStringList
+ for(int i=0; i<argv; i++) {
+ QString arg(argc[i]);
+ if(arg.compare(QString("-h"), Qt::CaseInsensitive) == 0) {
+ doHelp(&appName,&app);
+ return 0;
+ } else if(arg.compare(QString("-c"), Qt::CaseInsensitive) == 0) {
+ bComMode = true;
+ } else {
+ argList.append(arg);
+ }
+ }
+
+ if(bComMode) {
+ return doCommandLine(&argList, &app);
+ } else {
+ return doDialog(&argList, &app);
+ }
+}

Added: trunk/src/PlasmaGenerator/src/PlasmaGeneratorProfile.cpp
==============================================================================
--- (empty file)
+++ trunk/src/PlasmaGenerator/src/PlasmaGeneratorProfile.cpp Sat Mar 7
18:41:07 2009
@@ -0,0 +1,399 @@
+/**
+ * Copyright (c) 2009 Jeff Backus.
+ *
+ * Licensed under the GNU General Public License, Version 2.0
(the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Additionally, this code makes heavy use of the Qt libraries from
+ * Trolltech. These libraries are released under the GNU
+ * General Public License, Version 2.0, as well. Please contact
+ * Trolltech for more information.
+ *
+ * http://trolltech.com/
+ *
+ */
+
+// begin debug
+//#include <iostream>
+//using namespace std;
+// end debug
+
+#include <QtXml/QDomElement>
+#include <QtXml/QDomText>
+
+//#include "../../common/utility/misc_funcs.h"
+
+#include "utility/misc_funcs.h"
+#include "PlasmaGeneratorProfile.h"
+
+PlasmaGeneratorProfile::PlasmaGeneratorProfile() {
+
+ //defaults
+ _name = "Empty";
+ _palName = "";
+ _coarseness = 1.0;
+ _bClampColorIndex = true;
+ _bTileHorizontal = false;
+ _bTileVertical = false;
+ _height = 0;
+ _width = 0;
+ _targetFileName = "out.bmp";
+ _policy = ASK;
+}
+
+PlasmaGeneratorProfile::~PlasmaGeneratorProfile() {
+
+}
+
+/* Attempts to load this background profile object from the
+ * specified QDomNode.
+ */
+PlasmaGeneratorProfile* PlasmaGeneratorProfile::load(QDomNode &node) {
+ float tmpF;
+ int tmpI;
+ QDomElement tempElem;
+
+ //sanity check on the input
+ if(node.nodeName() != getXMLTagName())
+ return NULL;
+
+ PlasmaGeneratorProfile* retVal = new PlasmaGeneratorProfile();
+ if(retVal == NULL)
+ return NULL;
+
+ tempElem = node.firstChildElement("name");
+ if(!tempElem.isNull()) {
+ retVal->_name = tempElem.text();
+ }
+
+ tempElem = node.firstChildElement("palette");
+ if(!tempElem.isNull()) {
+ retVal->_palName = tempElem.text();
+ }
+
+ tempElem = node.firstChildElement("coarseness");
+ if(!tempElem.isNull()) {
+ tmpF = tempElem.text().toFloat();
+ if(tmpF > 0.00 && tmpF < 10000.00) {
+ retVal->_coarseness = tmpF;
+ }
+ }
+
+ tempElem = node.firstChildElement("clamp_color");
+ if(!tempElem.isNull()) {
+ QString param = tempElem.text();
+ retVal->_bClampColorIndex = stringToBool(param);
+ }
+
+ tempElem = node.firstChildElement("tile_horizontal");
+ if(!tempElem.isNull()) {
+ QString param = tempElem.text();
+ retVal->_bTileHorizontal = stringToBool(param);
+ }
+
+ tempElem = node.firstChildElement("tile_vertical");
+ if(!tempElem.isNull()) {
+ QString param = tempElem.text();
+ retVal->_bTileVertical = stringToBool(param);
+ }
+
+ tempElem = node.firstChildElement("height");
+ if(!tempElem.isNull()) {
+ tmpI = tempElem.text().toInt();
+ if(tmpI > 0 && tmpI < 10000) {
+ retVal->_height = tmpI;
+ }
+ }
+
+ tempElem = node.firstChildElement("width");
+ if(!tempElem.isNull()) {
+ tmpI = tempElem.text().toInt();
+ if(tmpI > 0 && tmpI < 10000) {
+ retVal->_width = tmpI;
+ }
+ }
+
+ tempElem = node.firstChildElement("target");
+ if(!tempElem.isNull()) {
+ retVal->_targetFileName = tempElem.text();
+ }
+
+ tempElem = node.firstChildElement("policy");
+ if(!tempElem.isNull()) {
+ if(tempElem.text().compare(QString("ALWAYS"), Qt::CaseInsensitive) ==
0) {
+ retVal->_policy = ALWAYS;
+ } else
+ if(tempElem.text().compare(QString("NEVER"), Qt::CaseInsensitive) ==
0) {
+ retVal->_policy = NEVER;
+ } else {
+ retVal->_policy = ASK;
+ }
+ }
+ return retVal;
+}
+
+
+/*
+ * Returns a QDomNode object that represents this profile.
+ */
+QDomNode PlasmaGeneratorProfile::save(QDomDocument* doc) {
+ QString tempStr;
+ QDomText tempNode;
+ QDomElement tempElem;
+ QDomElement retVal = doc->createElement(getXMLTagName());
+
+ //name
+ tempNode = doc->createTextNode(_name);
+ tempElem = doc->createElement("name");
+ tempElem.appendChild(tempNode);
+ retVal.appendChild(tempElem);
+
+ //palette name
+ tempNode = doc->createTextNode(_palName);
+ tempElem = doc->createElement("palette");
+ tempElem.appendChild(tempNode);
+ retVal.appendChild(tempElem);
+
+ //coarseness
+ tempStr.setNum(_coarseness);
+ tempNode = doc->createTextNode(tempStr);
+ tempElem = doc->createElement("coarseness");
+ tempElem.appendChild(tempNode);
+ retVal.appendChild(tempElem);
+
+ //clamp color index?
+ tempNode = doc->createTextNode(boolToString(_bClampColorIndex));
+ tempElem = doc->createElement("clamp_color");
+ tempElem.appendChild(tempNode);
+ retVal.appendChild(tempElem);
+
+ //tile horizontally?
+ tempNode = doc->createTextNode(boolToString(_bTileHorizontal));
+ tempElem = doc->createElement("tile_horizontal");
+ tempElem.appendChild(tempNode);
+ retVal.appendChild(tempElem);
+
+ //tile vertically?
+ tempNode = doc->createTextNode(boolToString(_bTileVertical));
+ tempElem = doc->createElement("tile_vertical");
+ tempElem.appendChild(tempNode);
+ retVal.appendChild(tempElem);
+
+ //height
+ tempStr.setNum(_height);
+ tempNode = doc->createTextNode(tempStr);
+ tempElem = doc->createElement("height");
+ tempElem.appendChild(tempNode);
+ retVal.appendChild(tempElem);
+
+ //width
+ tempStr.setNum(_width);
+ tempNode = doc->createTextNode(tempStr);
+ tempElem = doc->createElement("width");
+ tempElem.appendChild(tempNode);
+ retVal.appendChild(tempElem);
+
+ //target file name
+ tempNode = doc->createTextNode(_targetFileName);
+ tempElem = doc->createElement("target");
+ tempElem.appendChild(tempNode);
+ retVal.appendChild(tempElem);
+
+ //overwrite policy
+ switch(_policy) {
+ case ALWAYS:
+ tempNode = doc->createTextNode("ALWAYS");
+ break;
+ case NEVER:
+ tempNode = doc->createTextNode("NEVER");
+ break;
+ default:
+ tempNode = doc->createTextNode("ASK");
+ }
+ tempElem = doc->createElement("policy");
+ tempElem.appendChild(tempNode);
+ retVal.appendChild(tempElem);
+
+ return retVal;
+}
+
+/*
+ * Creates and returns a new PlasmaGenerator object. Does not
+ * generate the plasma.
+ */
+PlasmaGenerator* PlasmaGeneratorProfile::getGenerator(QHash<QString,
IndexedPaletteProfile*>* palHash) {
+
+ if(palHash == NULL)
+ return NULL;
+
+ PlasmaGenerator* retVal = new PlasmaGenerator();
+ if(retVal == NULL)
+ return NULL;
+
+ IndexedPaletteProfile* palProfile = palHash->value(_palName);
+ if(palProfile == NULL) {
+ delete retVal;
+ retVal = NULL;
+ return NULL;
+ }
+
+ IndexedPalette* pal = palProfile->createPalette();
+ if(pal == NULL) {
+ delete retVal;
+ retVal = NULL;
+ return NULL;
+ }
+
+ retVal->setHeight(_height);
+ retVal->setWidth(_width);
+ retVal->setPalette(*pal);
+ retVal->setClampColor(_bClampColorIndex);
+ retVal->setTileHorizontal(_bTileHorizontal);
+ retVal->setTileVertical(_bTileVertical);
+ retVal->setCoarseness(_coarseness);
+
+ // clean up
+ delete pal;
+ pal = NULL;
+
+ return retVal;
+}
+
+/*
+ * get/set palette name.
+ */
+QString PlasmaGeneratorProfile::getPaletteName() {
+ return _palName;
+}
+
+void PlasmaGeneratorProfile::setPaletteName(QString paletteName) {
+ _palName = paletteName;
+}
+
+/*
+ * get/set coarseness.
+ */
+float PlasmaGeneratorProfile::getCoarseness() {
+ return _coarseness;
+}
+
+void PlasmaGeneratorProfile::setCoarseness(float coarseness) {
+ _coarseness = coarseness;
+}
+
+/*
+ * Get/set clamp color index.
+ */
+bool PlasmaGeneratorProfile::getClampColorIndex() {
+ return _bClampColorIndex;
+}
+
+void PlasmaGeneratorProfile::setClampColorIndex(bool bClampColorIndex) {
+ _bClampColorIndex = bClampColorIndex;
+}
+
+/*
+ * Overloaded assignment operator
+ */
+PlasmaGeneratorProfile&
PlasmaGeneratorProfile::operator=(PlasmaGeneratorProfile& other) {
+ _name = other._name;
+ _palName = other._palName;
+ _coarseness = other._coarseness;
+ _bClampColorIndex = other._bClampColorIndex;
+ _bTileHorizontal = other._bTileHorizontal;
+ _bTileVertical = other._bTileVertical;
+ _height = other._height;
+ _width = other._width;
+ _targetFileName = other._targetFileName;
+ _policy = other._policy;
+
+ return *this;
+}
+
+/*
+ * Creates a new object with this object's settings.
+ */
+PlasmaGeneratorProfile* PlasmaGeneratorProfile::clone() {
+ PlasmaGeneratorProfile* retVal = new PlasmaGeneratorProfile();
+
+ *retVal = *this;
+
+ return retVal;
+}
+
+/**
+ * Called whenever palette names change
+ */
+void PlasmaGeneratorProfile::paletteNameChanged(QString oldName,
+ QString newName) {
+ // if the palette name matches the old name, change the name.
+ if(_palName == oldName) {
+ _palName = newName;
+ }
+}
+
+/**
+ * Called whenever a palette is removed.
+ */
+void PlasmaGeneratorProfile::paletteRemoved(QString palName) {
+ // if this palette has been removed, set current palette name to ""
+ if(_palName == palName) {
+ _palName = QString("");
+ }
+}
+
+/**
+ * Gets the current filename target.
+ */
+QString PlasmaGeneratorProfile::getFileTarget() {
+ return _targetFileName;
+}
+
+/**
+ * Sets the current filename target.
+ */
+void PlasmaGeneratorProfile::setFileTarget(QString filename) {
+ _targetFileName = filename;
+}
+
+/**
+ * Gets file overwrite policy.
+ */
+PlasmaGeneratorOverwritePolicy
PlasmaGeneratorProfile::getOverwritePolicy() {
+ return _policy;
+}
+
+/**
+ * Sets the file overwrite policy.
+ */
+void
PlasmaGeneratorProfile::setOverwritePolicy(PlasmaGeneratorOverwritePolicy
policy) {
+ _policy = policy;
+}
+
+
+/*
+ * Get/set the name of this profile.
+ */
+void PlasmaGeneratorProfile::setName(QString &name) {
+ _name = name;
+}
+QString PlasmaGeneratorProfile::getName() {
+ return _name;
+}
+
+/*
+ * Returns the tag name used by Dom elements for all
+ * subclasses of BackgroundProfile.
+ */
+QString PlasmaGeneratorProfile::getXMLTagName() {
+ return QString("PlasmaGeneratorProfile");
+}

Added: trunk/src/PlasmaGenerator/src/PlasmaGeneratorProfile.h
==============================================================================
--- (empty file)
+++ trunk/src/PlasmaGenerator/src/PlasmaGeneratorProfile.h Sat Mar 7
18:41:07 2009
@@ -0,0 +1,149 @@
+/**
+ * Copyright (c) 2009 Jeff Backus.
+ *
+ * Licensed under the GNU General Public License, Version 2.0
(the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Additionally, this code makes heavy use of the Qt libraries from
+ * Trolltech. These libraries are released under the GNU
+ * General Public License, Version 2.0, as well. Please contact
+ * Trolltech for more information.
+ *
+ * http://trolltech.com/
+ *
+ */
+
+/**
+ * This is the configuration profile for the PlasmaGenerator program.
+ *
+ * @author jeff backus
+ * @date 03/07/2009
+ */
+
+#ifndef __PLASMAGENERATORPROFILE_H__
+#define __PLASMAGENERATORPROFILE_H__
+
+#include <QString>
+#include <QHash>
+#include <QtXml/QDomNode>
+#include <QtXml/QDomDocument>
+
+#include "PlasmaGenerator.h"
+#include "IndexedPalette/IndexedPaletteProfile.h"
+
+enum PlasmaGeneratorOverwritePolicy{ALWAYS, NEVER, ASK};
+
+class PlasmaGeneratorProfile {
+
+ public:
+ PlasmaGeneratorProfile();
+ ~PlasmaGeneratorProfile();
+
+ /* Attempts to load this profile object from the
+ * specified QDomNode.
+ */
+ static PlasmaGeneratorProfile* load(QDomNode &node);
+
+ /*
+ * Returns a QDomNode object that represents this profile.
+ */
+ QDomNode save(QDomDocument* doc);
+
+ /*
+ * Creates and returns a new PlasmaGenerator object. Does not
+ * generate the plasma.
+ */
+ PlasmaGenerator* getGenerator(QHash<QString, IndexedPaletteProfile*>*
palHash);
+
+ /*
+ * get/set palette name.
+ */
+ QString getPaletteName();
+ void setPaletteName(QString paletteName);
+
+ /*
+ * get/set coarseness.
+ */
+ float getCoarseness();
+ void setCoarseness(float coarseness);
+
+ /*
+ * Get/set clamp color index.
+ */
+ bool getClampColorIndex();
+ void setClampColorIndex(bool bClampColorIndex);
+
+ /*
+ * Overloaded assignment operator.
+ */
+ PlasmaGeneratorProfile& operator=(PlasmaGeneratorProfile& other);
+
+ /*
+ * Creates a new object with this object's settings.
+ */
+ PlasmaGeneratorProfile* clone();
+
+ /**
+ * Called whenever palette names change
+ */
+ void paletteNameChanged(QString oldName, QString newName);
+
+ /**
+ * Called whenever a palette is removed.
+ */
+ void paletteRemoved(QString palName);
+
+ /**
+ * Gets the current filename target.
+ */
+ QString getFileTarget();
+
+ /**
+ * Sets the current filename target.
+ */
+ void setFileTarget(QString filename);
+
+ /**
+ * Gets file overwrite policy.
+ */
+ PlasmaGeneratorOverwritePolicy getOverwritePolicy();
+
+ /**
+ * Sets the file overwrite policy.
+ */
+ void setOverwritePolicy(PlasmaGeneratorOverwritePolicy policy);
+
+ /*
+ * Get/set the name of this profile.
+ */
+ void setName(QString &name);
+ QString getName();
+
+ /*
+ * Returns the tag name used by Dom elements for all
+ * subclasses of BackgroundProfile.
+ */
+ static QString getXMLTagName();
+
+ private:
+ QString _palName;
+ QString _name;
+ float _coarseness;
+ bool _bClampColorIndex;
+ bool _bTileHorizontal;
+ bool _bTileVertical;
+ int _height;
+ int _width;
+ QString _targetFileName;
+ PlasmaGeneratorOverwritePolicy _policy;
+};
+#endif

Modified: trunk/src/PlasmaGenerator/src/project_specific_extern_defs.h
==============================================================================
--- trunk/src/PlasmaGenerator/src/project_specific_extern_defs.h (original)
+++ trunk/src/PlasmaGenerator/src/project_specific_extern_defs.h Sat Mar 7
18:41:07 2009
@@ -1,5 +1,5 @@
/**
- * Copyright (c) 2008 Jeff Backus.
+ * Copyright (c) 2009 Jeff Backus.
*
* Licensed under the GNU General Public License, Version 2.0
(the "License");
* you may not use this file except in compliance with the License.
@@ -30,13 +30,13 @@
* other objects.
*
* Revision History:
- * 080214 jsbackus Initial revision.
+ * 090307 jsbackus Initial revision.
*/

#include <QString>

-#include "BackgroundProfile.h"
-#include "lens_engine/LensProfile.h"
+//#include "2d_bgnd_w_lens/BackgroundProfile.h"
+//#include "2d_bgnd_w_lens/lens_engine/LensProfile.h"

/**
* This function will create an array that contains the profiles
@@ -44,7 +44,7 @@
* the number of profiles in the array. If there is a problem,
* numProfiles will be set to 0 and NULL will be returned.
*/
-extern BackgroundProfile** getBackgroundTypes(int* numProfiles);
+//extern BackgroundProfile** getBackgroundTypes(int* numProfiles);

/**
* This function will create an array that contains the profiles
@@ -52,7 +52,7 @@
* the number of profiles in the array. If there is a problem,
* numProfiles will be set to 0 and NULL will be returned.
*/
-extern LensProfile** getLensTypes(int* numProfiles);
+//extern LensProfile** getLensTypes(int* numProfiles);

/**
* This function returns the string used to create the path for

Reply all
Reply to author
Forward
0 new messages