From f6ae6d5e16ea5add26f4012dd6150c9dbc68b062 Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Tue, 12 Nov 2019 22:17:26 +0000 Subject: [PATCH] - handle full path names git-svn-id: http://moon:8086/svn/software/trunk/projects/Rbm@661 b431acfa-c32f-4a4a-93f1-934dc6c82436 --- source/MainComponent.cpp | 7 ++++--- source/MainComponent.hpp | 2 ++ source/Stack.cpp | 20 +++++++++++--------- source/Stack.hpp | 3 ++- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/source/MainComponent.cpp b/source/MainComponent.cpp index c54e9eb..81cf1df 100644 --- a/source/MainComponent.cpp +++ b/source/MainComponent.cpp @@ -46,6 +46,7 @@ MainComponent::MainComponent (const String prjname) , m_trainingIndex(0) , m_weightIndex(0) , m_toolTipWindow(this) +, m_file(prjname) { addAndMakeVisible (trainButton = new TextButton ("Train button")); trainButton->setButtonText (TRANS("Train")); @@ -116,7 +117,7 @@ MainComponent::MainComponent (const String prjname) createButton->addListener (this); addAndMakeVisible (projectNameLabel = new Label ("Project Name label", - prjname)); + m_file.getFileNameWithoutExtension())); projectNameLabel->setFont (Font (15.00f, Font::plain)); projectNameLabel->setJustificationType (Justification::centred); projectNameLabel->setEditable (true, true, false); @@ -517,7 +518,7 @@ void MainComponent::buttonClicked (Button* buttonThatWasClicked) int numHid = numHiddenLabel->getText().getIntValue(); if (!m_stack) { - m_stack = new Stack(std::string(projectNameLabel->getText().getCharPointer())); + m_stack = new Stack(m_file.getParentDirectory().getFullPathName().toStdString(), std::string(projectNameLabel->getText().getCharPointer())); } m_stack->addLayer(onConstruct("Layer", next_index, numVisX, numVisY, numHid)); m_rbmSelect->addItem(String(next_index), next_index+1); @@ -527,7 +528,7 @@ void MainComponent::buttonClicked (Button* buttonThatWasClicked) else if (buttonThatWasClicked == loadButton) { //[UserButtonCode_loadButton] -- add your button handler code here.. - m_stack = new Stack(std::string(projectNameLabel->getText().getCharPointer())); + m_stack = new Stack(m_file.getParentDirectory().getFullPathName().toStdString(), std::string(projectNameLabel->getText().getCharPointer())); m_stack->load(this); m_stack->loadWeights(); m_rbmSelect->clear(dontSendNotification); diff --git a/source/MainComponent.hpp b/source/MainComponent.hpp index fe53d9f..7c9f805 100644 --- a/source/MainComponent.hpp +++ b/source/MainComponent.hpp @@ -93,6 +93,8 @@ private: String m_baseDir; TooltipWindow m_toolTipWindow; bool m_doStop; + juce::File m_file; + void clearTraining() { patterSlider->setRange(0, m_stack->numTraining()-1, 1); diff --git a/source/Stack.cpp b/source/Stack.cpp index 9b59f70..47b2482 100644 --- a/source/Stack.cpp +++ b/source/Stack.cpp @@ -15,14 +15,16 @@ using namespace std; -Stack::Stack(const std::string &name) -: m_name(name) +Stack::Stack(const std::string &dir, const std::string &name) +: m_dir(dir) +, m_name(name) , m_pLayers(nullptr) { } Stack::Stack(const Stack& orig) -: m_name(orig.m_name) +: m_dir(orig.m_dir) +, m_name(orig.m_name) , m_pLayers(orig.m_pLayers) { } @@ -92,7 +94,7 @@ Layer* Stack::getLayer(size_t layerId) const bool Stack::load(LayerConstructor *pLayerConstructor) { std::cout << "Importing Project " << m_name << std::endl; - ifstream ifs(m_name + string(".prj")); + ifstream ifs(m_dir + "/" + m_name + string(".prj")); Json::Reader reader; Json::Value project; @@ -132,7 +134,7 @@ bool Stack::load(LayerConstructor *pLayerConstructor) bool Stack::save() { std::cout << "Exporting Project " << m_name << std::endl; - ofstream ofs(m_name + string(".prj")); + ofstream ofs(m_dir + "/" + m_name + string(".prj")); Json::StyledWriter writer; Json::Value project; @@ -167,7 +169,7 @@ bool Stack::loadWeights() Layer *pLayer = m_pLayers; while(pLayer) { - if (!pLayer->loadWeights(m_name)) + if (!pLayer->loadWeights(m_dir + "/" + m_name)) { return false; } @@ -181,7 +183,7 @@ bool Stack::saveWeights() Layer *pLayer = m_pLayers; while(pLayer) { - if (!pLayer->saveWeights(m_name)) + if (!pLayer->saveWeights(m_dir + "/" + m_name)) { return false; } @@ -227,7 +229,7 @@ size_t Stack::loadTraining(bool doNormalize) uint32_t numTraining = 0; uint32_t numVisible = 0; - std::string filename = m_name + ".training.dat"; + std::string filename = m_dir + "/" + m_name + ".training.dat"; FILE *pFile = fopen(filename.c_str(), "r"); if (!pFile) @@ -273,7 +275,7 @@ size_t Stack::loadTraining(bool doNormalize) size_t Stack::saveTraining() { - std::string filename = m_name + ".training.dat"; + std::string filename = m_dir + "/" + m_name + ".training.dat"; FILE *pFile = fopen(filename.c_str(), "w"); if (!pFile) diff --git a/source/Stack.hpp b/source/Stack.hpp index 4eca74e..3506580 100644 --- a/source/Stack.hpp +++ b/source/Stack.hpp @@ -35,7 +35,7 @@ public: class Stack { public: - Stack(const std::string &name); + Stack(const std::string &dir, const std::string &name); Stack(const Stack& orig); virtual ~Stack(); @@ -60,6 +60,7 @@ public: arma::mat trainingData(Layer *pLayer); private: + std::string m_dir; std::string m_name; Layer *m_pLayers; arma::mat m_trainingData;