Permalink
Browse files

Added support for settings. And updated the Recording to handle Rigid…

… Body Marker Data.
  • Loading branch information...
mdfeist committed Jun 21, 2013
1 parent baec84f commit 439d3782d41ec552b08ae98e8b8968a99352cdf8
@@ -121,7 +121,7 @@
<Content Include="Images/*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
-<Content Include="Settings/*">
+ <Content Include="Settings/*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="ReadMe.txt" />
@@ -149,6 +149,7 @@
<ClCompile Include="RigidBody.cpp" />
<ClCompile Include="AppData.cpp" />
<ClCompile Include="SetObjectRigidBodyForm.cpp" />
+ <ClCompile Include="Settings.cpp" />
<ClCompile Include="Split.cpp" />
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
@@ -204,6 +205,7 @@
<FileType>CppForm</FileType>
</ClInclude>
<ClInclude Include="SetObjectRigidBodyFormController.h" />
+ <ClInclude Include="Settings.h" />
<ClInclude Include="Split.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="TCPClientListener.h" />
@@ -19,9 +19,7 @@
<None Include="app.ico">
<Filter>Resource Files</Filter>
</None>
- <None Include="DikablisHelpDocs\DikablisHelp.rtf">
- <Filter>Resource Files</Filter>
- </None>
+ <None Include="docs\DikablisHelp.rtf" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="BlinkAnalysis.cpp">
@@ -96,6 +94,9 @@
<ClCompile Include="RecordingManager.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="Settings.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="stdafx.h">
@@ -209,6 +210,9 @@
<ClInclude Include="RecordingManager.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="Settings.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="app.rc">
@@ -46,17 +46,29 @@ void MainFormController::showError(LPCTSTR msg) {
MessageBoxButtons::OK, MessageBoxIcon::Warning);
}
+std::string MainFormController::getSpecialFolderMyDocuments() {
+ msclr::interop::marshal_context context;
+ return context.marshal_as<std::string>(Environment::GetFolderPath(Environment::SpecialFolder::MyDocuments));
+}
+
void MainFormController::getFilePath(std::string& pathBuffer) {
+ getFilePath(pathBuffer, "");
+}
+
+void MainFormController::getFilePath(std::string& pathBuffer, std::string defaultPath) {
SaveFileDialog^ dialog = gcnew SaveFileDialog;
+ dialog->DefaultExt = "xml";
dialog->Filter = "XML files (*.xml)|*.xml|All files (*.*)|*.*";
dialog->FilterIndex = 2;
dialog->RestoreDirectory = true;
+ if (defaultPath != "") {
+ dialog->InitialDirectory = gcnew String(defaultPath.c_str());
+ }
+
if ( dialog->ShowDialog() == ::DialogResult::OK )
{
- MessageBox::Show(dialog->FileName);
-
msclr::interop::marshal_context context;
pathBuffer = context.marshal_as<std::string>(dialog->FileName);
}
@@ -14,6 +14,7 @@
#include "FormController.h"
using namespace System;
+using namespace System::IO;
public ref class MainFormController sealed :
public FormController<MainFormController^ volatile, BlinkAnalysis::MainForm^>
@@ -42,6 +43,8 @@ public ref class MainFormController sealed :
void objectUpdateGridView(int id) { this->form->objectUpdateGridView(id); }
void showError(LPCTSTR msg);
+ std::string getSpecialFolderMyDocuments();
void getFilePath(std::string& pathBuffer);
+ void getFilePath(std::string& pathBuffer, std::string defaultPath);
};
View
@@ -40,6 +40,9 @@ class Marker {
void setPosition(osg::Vec3 position) { this->position = position; }
osg::Vec3 getPosition() { return this->position; }
+ float& x() { return this->position.x(); }
+ float& y() { return this->position.y(); }
+ float& z() { return this->position.z(); }
void setRadius(float r) { this->radius = r; }
float getRadius() { return this->radius; }
View
@@ -4,6 +4,7 @@
#include "AppData.h"
#include "MainFormController.h"
#include "RecordingManager.h"
+#include "Settings.h"
typedef std::map<int, RigidBody*>::iterator RigidBody_iterator;
@@ -59,12 +60,24 @@ void XTrace(LPCTSTR lpszFormat, ...)
va_end(args);
}
+void CTrace(const char *format, ...)
+{
+ va_list args;
+ va_start(args, format);
+ int nBuf;
+ char szBuffer[512]; // get rid of this hard-coded buffer
+ nBuf = sprintf_s(szBuffer, 511, format, args);
+ ::OutputDebugStringA(szBuffer);
+ va_end(args);
+}
+
void Recording::initializeRecording() {
ClientHandler* client = AppData::getInstance()->getClient();
if (client) {
+ /*
UINT uRetVal = 0;
DWORD dwRetVal = 0;
// Get the temp path.
@@ -89,28 +102,45 @@ void Recording::initializeRecording() {
RecordingManager::getInstance()->stopRecording();
return;
}
+ */
+
+ OutputDebugStringA(Settings::getInstance()->getLastError());
+ OutputDebugStringA(Settings::getInstance()->getDefaultProjectDirectory().c_str());
std::string filePath;
- MainFormController::getInstance()->getFilePath(filePath);
+ MainFormController::getInstance()->getFilePath(filePath, Settings::getInstance()->getDefaultProjectDirectory());
//tempFileStream.open(szTempFileName);
- tempFileStream.open(filePath);
+ fileStream.open(filePath);
- if (tempFileStream.is_open()) {
+ if (fileStream.is_open()) {
- tempFileStream << "<Recording>\n";
- tempFileStream << "\t<StaticData>\n";
+ fileStream << "<Recording>\n";
+ fileStream << "<StaticData>\n";
+
+ // Lock the ClientHandler so data isn't changed
+ // by another thread.
+ if (!client->lock())
+ return;
+
std::map<int, RigidBody*>* rigidBodies = client->getRigidBodyMap();
for (RigidBody_iterator it = rigidBodies->begin(); it != rigidBodies->end(); ++it) {
- tempFileStream << "\t\t<RigidBody ";
- tempFileStream << "id=\"" << it->second->getID() << "\" ";
- tempFileStream << "name=\"" << it->second->getName() << "\" ";
- tempFileStream << "/>\n";
+ fileStream << "<RigidBody ";
+ fileStream << "id=\"" << it->second->getID() << "\" ";
+ fileStream << "name=\"" << it->second->getName() << "\" ";
+ fileStream << "/>\n";
}
- tempFileStream << "\t</StaticData>\n";
- tempFileStream << "\t<Frames>\n";
+ // Unlock the ClientHandler
+ client->unlock();
+
+ fileStream << "</StaticData>\n";
+ fileStream << "<Frames>\n";
+ } else {
+ MainFormController::getInstance()->showError(L"Failed to open file for recording.\n");
+ RecordingManager::getInstance()->stopRecording();
+ return;
}
}
@@ -121,41 +151,61 @@ void Recording:: addFrame() {
if (!this->readyForRecording)
initializeRecording();
- if (!tempFileStream.is_open())
+ if (!fileStream.is_open())
return;
ClientHandler* client = AppData::getInstance()->getClient();
if (client) {
- tempFileStream << "\t\t<Frame>\n";
+ fileStream << "<Frame>\n";
+
+ // Lock the ClientHandler so data isn't changed
+ // by another thread.
+ if (!client->lock())
+ return;
std::map<int, RigidBody*>* rigidBodies = client->getRigidBodyMap();
for (RigidBody_iterator it = rigidBodies->begin(); it != rigidBodies->end(); ++it) {
- tempFileStream << "\t\t\t<RigidBody \n";
+ fileStream << "<RigidBody ";
- tempFileStream << "id=\"" << it->second->getID() << "\" ";
+ fileStream << "id=\"" << it->second->getID() << "\" ";
+
+ fileStream << "x=\"" << it->second->getPosition().x() << "\" ";
+ fileStream << "y=\"" << it->second->getPosition().y() << "\" ";
+ fileStream << "z=\"" << it->second->getPosition().z() << "\" ";
- tempFileStream << "x=\"" << it->second->getPosition().x() << "\" ";
- tempFileStream << "y=\"" << it->second->getPosition().y() << "\" ";
- tempFileStream << "z=\"" << it->second->getPosition().z() << "\" ";
+ fileStream << "qx=\"" << it->second->getRotation().x() << "\" ";
+ fileStream << "qy=\"" << it->second->getRotation().y() << "\" ";
+ fileStream << "qz=\"" << it->second->getRotation().z() << "\" ";
+ fileStream << "qw=\"" << it->second->getRotation().w() << "\" ";
- tempFileStream << "qx=\"" << it->second->getRotation().x() << "\" ";
- tempFileStream << "qy=\"" << it->second->getRotation().y() << "\" ";
- tempFileStream << "qz=\"" << it->second->getRotation().z() << "\" ";
- tempFileStream << "qw=\"" << it->second->getRotation().w() << "\" ";
+ fileStream << ">\n";
- tempFileStream << "/>\n";
+ std::vector<Marker>* markers = it->second->getMarkersVector();
+
+ for (unsigned int i = 0; i < markers->size(); i++) {
+ fileStream << "<Marker ";
+ fileStream << "x=\"" << (*markers)[i].x() << "\" ";
+ fileStream << "y=\"" << (*markers)[i].y() << "\" ";
+ fileStream << "z=\"" << (*markers)[i].z() << "\" ";
+ fileStream << "/>\n";
+ }
+
+ fileStream << "</RigidBody>\n";
}
+
+ // Unlock the ClientHandler
+ client->unlock();
- tempFileStream << "\t\t</Frame>\n";
+ fileStream << "</Frame>\n";
}
}
void Recording::closeRecording() {
- if (tempFileStream.is_open()) {
- tempFileStream << "\t</Frames>\n";
- tempFileStream << "</Recording>\n";
- tempFileStream.close();
+ if (fileStream.is_open()) {
+ fileStream << "</Frames>\n";
+ fileStream << "</Recording>\n";
+ fileStream.close();
}
}
@@ -120,7 +120,7 @@ class Recording
void initializeRecording();
- std::ofstream tempFileStream;
+ std::ofstream fileStream;
TCHAR szTempFileName[MAX_PATH];
TCHAR lpTempPathBuffer[MAX_PATH];
View
@@ -0,0 +1,66 @@
+#include "StdAfx.h"
+#include "Settings.h"
+
+#include "MainFormController.h"
+
+Settings* Settings::m_pInstance = NULL;
+
+Settings::Settings(void)
+{
+ sprintf_s(this->error, "No Error");
+ this->defaultProjectDirectory = "";
+ loadSettings();
+}
+
+
+Settings::~Settings(void)
+{
+}
+
+bool Settings::loadSettings() {
+ pugi::xml_document doc;
+ pugi::xml_parse_result result = doc.load_file("Settings/Settings.xml");
+
+ if (result.status) {
+ sprintf_s(this->error, "Load Setting Result: %s.", result.description());
+ return false;
+ } else {
+
+ // Get Settings
+ pugi::xml_node settings = doc.child("Settings");
+
+ if (settings) {
+
+ pugi::xml_node defaultProjectDirectory_node = settings.child("DefaultProjectDirectory");
+
+ if (defaultProjectDirectory_node) {
+
+ pugi::xml_attribute defaultProjectDirectory_path = defaultProjectDirectory_node.attribute("path");
+
+ if (defaultProjectDirectory_path) {
+ defaultProjectDirectory = defaultProjectDirectory_path.value();
+ std::string myDocumentsKey("[MyDocuments]");
+
+ /* Locate the substring to replace. */
+ int index = defaultProjectDirectory.find(myDocumentsKey);
+ if (index != std::string::npos) {
+ /* Make the replacement. */
+ std::string myDocuments = MainFormController::getInstance()->getSpecialFolderMyDocuments();
+ defaultProjectDirectory.replace(index, myDocumentsKey.length(), myDocuments);
+ }
+ } else {
+ sprintf_s(this->error, "Can not find the path attribute for DefaultProjectDirectory node.");
+ return false;
+ }
+ } else {
+ sprintf_s(this->error, "Can not find DefaultProjectDirectory node.");
+ return false;
+ }
+ } else {
+ sprintf_s(this->error, "Can not find Settings node.");
+ return false;
+ }
+ }
+
+ return true;
+}
View
@@ -0,0 +1,34 @@
+#pragma once
+#include "stdafx.h"
+#include <string>
+
+#include "pugixml.hpp"
+
+class Settings
+{
+public:
+ static Settings* getInstance() {
+ if(!m_pInstance) m_pInstance = new Settings();
+ return m_pInstance;
+ }
+
+ char* getLastError() { return this->error; }
+
+ bool loadSettings();
+
+ std::string getDefaultProjectDirectory() { return this->defaultProjectDirectory; }
+
+protected:
+ Settings(void);
+ ~Settings(void);
+private:
+ Settings(Settings const&);
+ Settings& operator=(Settings const&);
+
+ static Settings* m_pInstance;
+
+ char error[1024];
+
+ std::string defaultProjectDirectory;
+};
+

0 comments on commit 439d378

Please sign in to comment.