From 9b186aeddf1405fd1b6c3ea9eedf3fa3a23f4fce Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sacha=20Percot-T=C3=A9tu?= <zakinster@zakinster.com>
Date: Tue, 25 Sep 2012 18:08:00 +0200
Subject: [PATCH] Compilation corrections, minor bug corrections

---
 app/Operations/PointOp.h              | 14 +++++++-------
 app/Services/EIImageService.cpp       |  9 +++++++--
 app/Services/EIImageService.h         |  1 +
 app/Services/PluginManager.cpp        | 18 ++++++++++++++++--
 app/Services/PluginManager.h          |  2 ++
 app/main.cpp                          |  1 -
 core/IntParam.cpp                     |  2 +-
 core/Operation.cpp                    |  5 +++--
 core/Operation.h                      |  6 +++---
 plugins/Segmentation/segmentation.cpp |  1 -
 10 files changed, 40 insertions(+), 19 deletions(-)

diff --git a/app/Operations/PointOp.h b/app/Operations/PointOp.h
index dec846e..8ba7acd 100644
--- a/app/Operations/PointOp.h
+++ b/app/Operations/PointOp.h
@@ -84,7 +84,7 @@ class PointOp : public GenericOperation {
     };
 
     struct PixAdd : PixOp_t<int> {
-        PixAdd(int value_) : PixOp_t(value_) {}
+        PixAdd(int value_) : PixOp_t<int>(value_) {}
         intmax_t op(depth_t pixel) { return pixel + value; }
     };
     struct DoublePixAdd : DoublePixelOp {
@@ -93,7 +93,7 @@ class PointOp : public GenericOperation {
     };
 
     struct PixMul : PixOp_t<double> {
-        PixMul(double value_) : PixOp_t(value_) {}
+        PixMul(double value_) : PixOp_t<double>(value_) {}
         intmax_t op(depth_t pixel) { return pixel * value + 0.5; }
     };
     struct DoublePixMul : DoublePixelOp {
@@ -102,27 +102,27 @@ class PointOp : public GenericOperation {
     };
 
     struct PixAnd : PixOp_t<depth_t> {
-        PixAnd(depth_t value_) : PixOp_t(value_) {}
+        PixAnd(depth_t value_) : PixOp_t<depth_t>(value_) {}
         intmax_t op(depth_t pixel) { return pixel & value; }
     };
 
     struct PixOr : PixOp_t<depth_t> {
-        PixOr(depth_t value_) : PixOp_t(value_) {}
+        PixOr(depth_t value_) : PixOp_t<depth_t>(value_) {}
         intmax_t op(depth_t pixel) { return pixel | value; }
     };
 
     struct PixXor : PixOp_t<depth_t> {
-        PixXor(depth_t value_) : PixOp_t(value_) {}
+        PixXor(depth_t value_) : PixOp_t<depth_t>(value_) {}
         intmax_t op(depth_t pixel) { return pixel ^ value; }
     };
 
     struct PixLshift : PixOp_t<unsigned int> {
-        PixLshift(unsigned int value_) : PixOp_t(value_) {}
+        PixLshift(unsigned int value_) : PixOp_t<unsigned int>(value_) {}
         intmax_t op(depth_t pixel) { return pixel << value; }
     };
     
     struct PixRshift : PixOp_t<unsigned int> {
-        PixRshift(unsigned int value_) : PixOp_t(value_) {}
+        PixRshift(unsigned int value_) : PixOp_t<unsigned int>(value_) {}
         intmax_t op(depth_t pixel) { return pixel >> value; }
     };
 
diff --git a/app/Services/EIImageService.cpp b/app/Services/EIImageService.cpp
index 1a1b2d0..20c430b 100644
--- a/app/Services/EIImageService.cpp
+++ b/app/Services/EIImageService.cpp
@@ -69,9 +69,8 @@ void EIImageService::addOpSet(OpSet* opSet) {
 void EIImageService::removeOpSet(OpSet* opSet) {
     for(vector<OpSetService*>::iterator it = _opSetServices.begin(); it != _opSetServices.end(); ++it) {
         if((*it)->getOpSet() == opSet) {
-            _opSetServices.erase(it);
             _gi->removeService(*it);
-            delete *it;
+            _opSetServices.erase(it);
             return;
         }
     }
@@ -83,3 +82,9 @@ void EIImageService::outputText(QString text) {
     if(_statusEdit->minimumHeight() < 92) _statusEdit->setMinimumHeight(_statusEdit->minimumHeight()+24);
 //    _statusEdit->setMinimumHeight(32);
 }
+
+void EIImageService::addText(std::string s) {
+    _statusEdit->append(QString::fromStdString(s));
+    _statusEdit->show();
+    if(_statusEdit->minimumHeight() < 92) _statusEdit->setMinimumHeight(_statusEdit->minimumHeight()+24);
+}
diff --git a/app/Services/EIImageService.h b/app/Services/EIImageService.h
index dfc0fce..18de689 100644
--- a/app/Services/EIImageService.h
+++ b/app/Services/EIImageService.h
@@ -42,6 +42,7 @@ class EIImageService : public genericinterface::WindowService
     void addOpSet(OpSet* opSet);
     void removeOpSet(OpSet* opSet);
     void outputText(QString text);
+    virtual void addText(std::string);
 
   private:  
     genericinterface::GenericInterface* _gi;
diff --git a/app/Services/PluginManager.cpp b/app/Services/PluginManager.cpp
index d5063af..bda6322 100644
--- a/app/Services/PluginManager.cpp
+++ b/app/Services/PluginManager.cpp
@@ -128,7 +128,14 @@ void PluginManager::choosePlugin() {
 }
 void PluginManager::unloadAllPlugins() {
     for(std::map<string, Plugin*>::iterator it = _plugins.begin(); it != _plugins.end(); ++it) {
-        emit removePlugin(it->second);
+        Plugin* plugin = it->second;
+        map<Plugin*,QLibrary*>::iterator lit = _libraries.find(plugin);
+        if(lit != _libraries.end()) {
+            bool res = lit->second->unload();
+            std::cout << "Unloading " << lit->second->fileName().toStdString() << "..." << res << std::endl;
+            _libraries.erase(lit);
+        }
+        emit removePlugin(plugin);
     }
     _plugins.clear();
     checkActionsValid();
@@ -140,8 +147,14 @@ void PluginManager::unloadPlugin(Plugin* plugin) {
             //delete it->second;
             //_pluginServices.erase(it);
             ////it = _pluginServices.begin();
-            _plugins.erase(it->first);
+            map<Plugin*,QLibrary*>::iterator lit = _libraries.find(plugin);
+            if(lit != _libraries.end()) {
+                bool res = lit->second->unload();
+                std::cout << "Unloading " << lit->second->fileName().toStdString() << "..." << res << std::endl;
+                _libraries.erase(lit);
+            }
             emit removePlugin(plugin);
+            _plugins.erase(it);
             checkActionsValid();
             return;
         }
@@ -191,6 +204,7 @@ bool PluginManager::loadPlugin(QString file, bool silent) {
     
     //PluginService* pluginService = new PluginService(plugin);
     _plugins.insert(pair<string,Plugin*>(file.toStdString(), plugin));
+    _libraries.insert(pair<Plugin*,QLibrary*>(plugin, library));
     //_gi->addService(pluginService);
     emit addPlugin(plugin);
     checkActionsValid();
diff --git a/app/Services/PluginManager.h b/app/Services/PluginManager.h
index b88b7ea..6837c45 100644
--- a/app/Services/PluginManager.h
+++ b/app/Services/PluginManager.h
@@ -26,6 +26,7 @@
 #include <Services/AlgorithmService.h>
 
 #include <QToolBar>
+class QLibrary;
 
 #include "OpSetService.h"
 
@@ -52,6 +53,7 @@ class PluginManager : public QObject, public genericinterface::Service
     QAction* _loadPluginAction;
     QAction* _unloadPluginsAction;
     std::map<std::string, Plugin*> _plugins;
+    std::map<Plugin*, QLibrary*> _libraries;
     void checkActionsValid();
 };
 
diff --git a/app/main.cpp b/app/main.cpp
index f379c58..38015a4 100644
--- a/app/main.cpp
+++ b/app/main.cpp
@@ -30,7 +30,6 @@
 #include "Services/PluginManager.h"
 #include "Services/EIImageService.h"
 
-#include "Operations/TestOp.h"
 #include "Operations/PointOp.h"
 #include "Operations/ThresholdOp.h"
 #include "Operations/TranslateOp.h"
diff --git a/core/IntParam.cpp b/core/IntParam.cpp
index 4566388..c7134a0 100644
--- a/core/IntParam.cpp
+++ b/core/IntParam.cpp
@@ -29,7 +29,7 @@ using namespace imagein;
 using namespace std;
 using namespace genericinterface;
 
-IntParam::IntParam(std::string name, int min, int max, int def) : Parameter(name), _min(min), _max(max) {
+IntParam::IntParam(std::string name, int min, int max, int def) : Parameter<int>(name), _min(min), _max(max) {
     _def = std::min(def, _max);
     _def = std::max(def, _min);
 }
diff --git a/core/Operation.cpp b/core/Operation.cpp
index 698bc4e..129e265 100644
--- a/core/Operation.cpp
+++ b/core/Operation.cpp
@@ -20,6 +20,7 @@
 #include "Operation.h"
 #include <Widgets/ImageWidgets/StandardImageWindow.h>
 #include <Widgets/ImageWidgets/DoubleImageWindow.h>
+#include <Services/WindowService.h>
 
 using namespace std;
 using namespace imagein;
@@ -33,7 +34,7 @@ class EIImageService : public genericinterface::WindowService
     void outputText(QString text);
 };
 
-void GenericOperation::operator()(EIImageService* ws) {
+void GenericOperation::operator()(WindowService* ws) {
     _ws = ws;
     _curImgWnd = ws->getCurrentImageWindow();
     vector<const ImageWindow*> wndList = ws->getImageWindows();
@@ -74,7 +75,7 @@ void GenericOperation::outDoubleImage(imagein::Image_t<double>* img, string titl
 
 void GenericOperation::outText(std::string text) {
     if(_ws == NULL) return;
-    _ws->outputText(QString(text.c_str()));
+    _ws->addText(text);
 }
 
 void Operation::operator()(const ImageWindow* currentWnd, const vector<const ImageWindow*>& wndList) {
diff --git a/core/Operation.h b/core/Operation.h
index bc98465..148a194 100644
--- a/core/Operation.h
+++ b/core/Operation.h
@@ -26,9 +26,9 @@
 #include "Image.h"
 
 class QWidget;
-class EIImageService;
 namespace genericinterface {
     class ImageWindow;
+    class WindowService;
 }
 
 /**
@@ -68,7 +68,7 @@ class GenericOperation {
      *
      * @param ws The eiimage implementation of the genericinterface::WindowService
      */
-    virtual void operator()(EIImageService* ws);
+    virtual void operator()(genericinterface::WindowService* ws);
 
     /**
      * @brief This method should return wether this Operation need the currentWnd parameter.
@@ -131,7 +131,7 @@ class GenericOperation {
     void outText(std::string);
 
     std::string _name; /**< The name of the operation */
-    EIImageService* _ws; /**< A pointer to the eiimage window service, only valid inside the function call operator */
+    genericinterface::WindowService* _ws; /**< A pointer to the eiimage window service, only valid inside the function call operator */
     genericinterface::ImageWindow* _curImgWnd; /**< A pointer to the current image window, only valid inside the function call operator */
   private:
     /**
diff --git a/plugins/Segmentation/segmentation.cpp b/plugins/Segmentation/segmentation.cpp
index 3cfe55b..36b8a3f 100644
--- a/plugins/Segmentation/segmentation.cpp
+++ b/plugins/Segmentation/segmentation.cpp
@@ -30,7 +30,6 @@
 #include "Plugin.h"
 #include "ImgParam.h"
 #include "IntParam.h"
-#include "ImgOutput.h"
 
 using namespace std;
 using namespace imagein;
-- 
GitLab