[med-svn] [aghermann] 26/31: enable global score operation

andrei zavada hmmr-guest at alioth.debian.org
Sun Nov 10 00:34:19 UTC 2013


This is an automated email from the git hooks/post-receive script.

hmmr-guest pushed a commit to branch WIP
in repository aghermann.

commit 769e8abfd6f915c3f96edf73fa939a91e1a60027
Author: Andrei Zavada <hmmr at ra>
Date:   Sun Nov 10 01:54:08 2013 +0200

    enable global score operation
---
 upstream/data/mw.glade                       |   22 +++-
 upstream/src/aghermann/expdesign/dirlevel.hh |   12 ++
 upstream/src/aghermann/ui/mw/construct.cc    |   17 +++
 upstream/src/aghermann/ui/mw/mainmenu_cb.cc  |  163 ++++++++++++++++++++++++--
 upstream/src/aghermann/ui/mw/mw_cb.hh        |    2 +
 upstream/src/aghermann/ui/mw/widgets.hh      |   14 +++
 upstream/src/libsigfile/page.hh              |   10 ++
 7 files changed, 231 insertions(+), 9 deletions(-)

diff --git a/upstream/data/mw.glade b/upstream/data/mw.glade
index 74a4f21..8e3f483 100644
--- a/upstream/data/mw.glade
+++ b/upstream/data/mw.glade
@@ -819,6 +819,14 @@ rm */*/*/.*.{psd,mc,swu}</property>
                                               </object>
                                             </child>
                                             <child>
+                                              <object class="GtkMenuItem" id="iExpGloballyScore">
+                                                <property name="visible">True</property>
+                                                <property name="can_focus">False</property>
+                                                <property name="label" translatable="yes">_Score...</property>
+                                                <property name="use_underline">True</property>
+                                              </object>
+                                            </child>
+                                            <child>
                                               <object class="GtkMenuItem" id="iExpGloballyDetectArtifacts">
                                                 <property name="visible">True</property>
                                                 <property name="can_focus">False</property>
@@ -1406,7 +1414,7 @@ rm */*/*/.*.{psd,mc,swu}</property>
                         </child>
                         <child>
                           <object class="GtkButton" id="bMainCloseThatSF">
-                            <property name="label" translatable="yes">button</property>
+                            <property name="label" translatable="yes">close that SF hidden button</property>
                             <property name="can_focus">True</property>
                             <property name="receives_default">True</property>
                             <property name="no_show_all">True</property>
@@ -7488,6 +7496,18 @@ dragging individual signals with <i>Alt</i>.</small></property
                                     <child>
                                       <placeholder/>
                                     </child>
+                                    <child>
+                                      <placeholder/>
+                                    </child>
+                                    <child>
+                                      <placeholder/>
+                                    </child>
+                                    <child>
+                                      <placeholder/>
+                                    </child>
+                                    <child>
+                                      <placeholder/>
+                                    </child>
                                   </object>
                                 </child>
                                 <child>
diff --git a/upstream/src/aghermann/expdesign/dirlevel.hh b/upstream/src/aghermann/expdesign/dirlevel.hh
index 3106c7c..e9f8d43 100644
--- a/upstream/src/aghermann/expdesign/dirlevel.hh
+++ b/upstream/src/aghermann/expdesign/dirlevel.hh
@@ -86,6 +86,18 @@ class CStorablePPack {
                         return *this;
                 }
 
+        bool
+        operator==( const CStorablePPack& rv)
+                {
+                        return  subdir == rv.subdir &&
+                                name == rv.name &&
+                                level == rv.level &&
+                                level_id.g == rv.level_id.g &&
+                                level_id.j == rv.level_id.j &&
+                                level_id.d == rv.level_id.d &&
+                                saved == rv.saved;
+                }
+
         string  subdir,
                 name;
         TExpDirLevel
diff --git a/upstream/src/aghermann/ui/mw/construct.cc b/upstream/src/aghermann/ui/mw/construct.cc
index 595d28d..2f329e1 100644
--- a/upstream/src/aghermann/ui/mw/construct.cc
+++ b/upstream/src/aghermann/ui/mw/construct.cc
@@ -48,6 +48,9 @@ SExpDesignUIWidgets ()
                                     G_TYPE_BOOLEAN, G_TYPE_POINTER);
         mGlobalADProfiles =
                 gtk_list_store_new( 1, G_TYPE_STRING);
+        mGlobalRKProfiles =
+                gtk_list_store_new( 1, G_TYPE_STRING);
+
         mSimulations =
                 gtk_tree_store_new( 16,
                                     G_TYPE_STRING,        // group, subject, channel, from-upto
@@ -104,6 +107,7 @@ SExpDesignUIWidgets ()
         AGH_GBGETOBJ (iExpSubjectSortSegregate);
         AGH_GBGETOBJ (iExpBasicSADetectUltradianCycles);
         AGH_GBGETOBJ (iiExpGlobalOperations);
+        AGH_GBGETOBJ (iExpGloballyScore);
         AGH_GBGETOBJ (iExpGloballyDetectArtifacts);
         AGH_GBGETOBJ (iExpGloballySetFilters);
         AGH_GBGETOBJ (iiExpSubjectSort);
@@ -121,6 +125,7 @@ SExpDesignUIWidgets ()
         G_CONNECT_1 (iExpPurgeComputed, activate);
         G_CONNECT_1 (iExpAnnotations, activate);
         G_CONNECT_1 (iExpBasicSADetectUltradianCycles, activate);
+        G_CONNECT_1 (iExpGloballyScore, activate);
         G_CONNECT_1 (iExpGloballyDetectArtifacts, activate);
         G_CONNECT_1 (iExpGloballySetFilters, activate);
         // G_CONNECT_1 (iMontageSetDefaults, activate);
@@ -625,6 +630,17 @@ SExpDesignUIWidgets ()
 
         G_CONNECT_1 (eGlobalAnnotationsShowPhasicEvents, toggled);
 
+      // ------------- wGlobalScore
+        AGH_GBGETOBJ (wGlobalScore);
+        AGH_GBGETOBJ (eGlobalRKProfiles);
+        AGH_GBGETOBJ (eGlobalRKKeepExisting);
+        AGH_GBGETOBJ (bGlobalRKOK);
+        AGH_GBGETOBJ (lGlobalRKHint);
+
+        gtk_combo_box_set_model_properly(
+                eGlobalRKProfiles, mGlobalRKProfiles);
+        G_CONNECT_1 (eGlobalRKProfiles, changed);
+
       // ------------- wGlobalArtifactDetection
         AGH_GBGETOBJ (wGlobalArtifactDetection);
         AGH_GBGETOBJ (eGlobalADProfiles);
@@ -659,6 +675,7 @@ SExpDesignUIWidgets::
         g_object_unref( (GObject*)mAllChannels);
         g_object_unref( (GObject*)mSessions);
         g_object_unref( (GObject*)mGlobalAnnotations);
+        g_object_unref( (GObject*)mGlobalRKProfiles);
         g_object_unref( (GObject*)mGlobalADProfiles);
         g_object_unref( (GObject*)mSimulations);
 
diff --git a/upstream/src/aghermann/ui/mw/mainmenu_cb.cc b/upstream/src/aghermann/ui/mw/mainmenu_cb.cc
index 1a82753..478c4c5 100644
--- a/upstream/src/aghermann/ui/mw/mainmenu_cb.cc
+++ b/upstream/src/aghermann/ui/mw/mainmenu_cb.cc
@@ -10,6 +10,7 @@
  */
 
 #include "aghermann/artifact-detection/3in1.hh"
+#include "aghermann/rk1968/rk1968.hh"
 #include "aghermann/ui/misc.hh"
 #include "aghermann/ui/sm/sm.hh"
 #include "aghermann/ui/sf/sf.hh"
@@ -207,13 +208,13 @@ iExpBasicSADetectUltradianCycles_activate_cb(
         ED.sb_clear();
 }
 
+} // extern "C"
 
 
 
-
-
-static void
-populate_combo( const list<agh::ad::CComprehensiveArtifactDetector>& profiles, GtkListStore* mProfiles)
+template <class C>
+void
+populate_combo( const list<C>& profiles, GtkListStore* mProfiles)
 {
         gtk_list_store_clear( mProfiles);
 
@@ -231,11 +232,12 @@ populate_combo( const list<agh::ad::CComprehensiveArtifactDetector>& profiles, G
 }
 
 
-static list<agh::ad::CComprehensiveArtifactDetector>::const_iterator
-profile_by_idx( const list<agh::ad::CComprehensiveArtifactDetector>& profiles, size_t idx)
+template <class C>
+typename list<C>::iterator
+profile_by_idx( list<C>& profiles, size_t idx)
 {
         size_t i = 0;
-        for ( auto I = profiles.cbegin(); I != profiles.cend(); ++I )
+        for ( auto I = profiles.begin(); I != profiles.end(); ++I )
                 if ( i == idx )
                         return I;
                 else
@@ -243,6 +245,139 @@ profile_by_idx( const list<agh::ad::CComprehensiveArtifactDetector>& profiles, s
         throw invalid_argument ("Current profile index invalid");
 }
 
+
+extern "C" {
+
+void
+iExpGloballyScore_activate_cb(
+        GtkMenuItem*,
+        const gpointer userdata)
+{
+        auto& ED = *(SExpDesignUI*)userdata;
+
+        using namespace agh;
+        using agh::rk1968::CScoreAssistant;
+        list<CScoreAssistant> profiles;
+
+        for ( auto A : {TExpDirLevel::system, TExpDirLevel::user, TExpDirLevel::experiment} )
+                profiles.splice(
+                        profiles.end(),
+                        load_profiles_from_location<CScoreAssistant>(
+                                CScoreAssistant::common_subdir,
+                                A, *ED.ED, agh::SExpDirLevelId {"", "", ""}));
+
+        bool must_select_first = false;
+        if ( profiles.empty() ) {
+                profiles.emplace_back( *ED.ED, agh::SExpDirLevelId {"", "", ""}), must_select_first = true;
+        } else {
+                int previously_selected = gtk_combo_box_get_active( ED.eGlobalADProfiles);
+                if ( (int)profiles.size() < previously_selected ||  // user has deleted some since we last displayed
+                     previously_selected == -1 )
+                must_select_first = true;
+        }
+
+        populate_combo( profiles, ED.mGlobalRKProfiles);
+        gtk_combo_box_set_model( ED.eGlobalRKProfiles, (GtkTreeModel*)ED.mGlobalRKProfiles);
+        if ( must_select_first )
+                gtk_combo_box_set_active( ED.eGlobalRKProfiles, 0);
+
+        gtk_label_set_markup(
+                ED.lGlobalRKHint,
+                (profiles.size() < 2)
+                ? "<small>You can create a custom profile in Scoring Facility,\n"
+                  "after tuning parameters on a real recording.</small>"
+                : ""); // good boy
+
+
+        auto response = gtk_dialog_run( ED.wGlobalScore);
+        if ( GTK_RESPONSE_CANCEL == response ||
+             GTK_RESPONSE_DELETE_EVENT == response )
+                return; // just to save on indents in those lambdas below
+
+        auto P =
+                profile_by_idx(
+                        profiles,
+                        gtk_combo_box_get_active( ED.eGlobalRKProfiles));
+        bool keep_existing = gtk_toggle_button_get_active( (GtkToggleButton*)ED.eGlobalRKKeepExisting);
+
+        SBusyBlock bb (ED.wMainWindow);
+
+        using namespace agh;
+        CExpDesign::TEpisodeOpFun op;
+        CExpDesign::TEpisodeFilterFun filter;
+        CExpDesign::TEpisodeReportFun reporter =
+                [&]( const CJGroup&, const CSubject& J, const string& D, const SEpisode& E,
+                     size_t i, size_t total)
+                {
+                        ED.sb_main_progress_indicator(
+                                snprintf_buf(
+                                        "Score %s/%s/%s/%s",
+                                        ED.ED->group_of(J), J.id.c_str(), D.c_str(), E.name()),
+                                total, i, TGtkRefreshMode::gtk);
+                };
+        switch ( response ) {
+        case GTK_RESPONSE_OK:
+                op =
+                [&]( SEpisode& E)
+                {
+                        if ( not keep_existing )
+                                for ( auto& F : E.sources )
+                                        F.CHypnogram::clear();
+// // lua uses global state, is not reentrant
+// #ifdef _OPENMP
+// #pragma omp critical
+// #endif
+// #ifdef _OPENMP
+                        CScoreAssistant (*P) // new instance for each run
+                                . score( E, nullptr);
+                };
+                filter =
+                [&]( SEpisode& E)
+                {
+                        return true;  // R.signal_type() == sigfile::SChannel::TType::eeg;
+                };
+            break;
+
+        case 1:  // "Clear All"
+                op =
+                [&]( SEpisode& E)
+                {
+                        for ( auto& F : E.sources )
+                                F.CHypnogram::clear();
+                };
+                filter =
+                [&]( SEpisode&)
+                {
+                        return true; // clear in all channels (mark in EEG channels only)
+                };
+            break;
+        default:
+                throw runtime_error ("Fix dialog response?");
+        }
+
+        forward_list<SBusyBlock*> bbl;
+        for ( auto& SFp : ED.open_scoring_facilities )
+                bbl.push_front( new SBusyBlock (SFp->wSF));
+
+        ED.ED -> for_all_episodes( op, reporter, filter);
+        ED.sb_clear();
+
+        FAFA;
+        for ( auto& SF : ED.open_scoring_facilities ) {
+                for ( auto& H : SF->channels )
+                        if ( H.type() == sigfile::SChannel::TType::eeg )
+                                H.get_signal_filtered();
+                SF->queue_redraw_all();
+        }
+
+        ED.populate_1();
+
+        for ( auto& bb : bbl )
+                delete bb;
+}
+
+
+
 void
 iExpGloballyDetectArtifacts_activate_cb(
         GtkMenuItem*,
@@ -349,7 +484,7 @@ iExpGloballyDetectArtifacts_activate_cb(
                 };
             break;
         default:
-                throw runtime_error ("Fix AD dialog response?");
+                throw runtime_error ("Fix dialog response?");
         }
 
         forward_list<SBusyBlock*> bbl;
@@ -373,6 +508,18 @@ iExpGloballyDetectArtifacts_activate_cb(
 }
 
 void
+eGlobalRKProfiles_changed_cb(
+        GtkComboBox*,
+        const gpointer userdata)
+{
+        auto& ED = *(SExpDesignUI*)userdata;
+
+        gtk_widget_set_sensitive(
+                (GtkWidget*)ED.bGlobalRKOK,
+                gtk_combo_box_get_active( ED.eGlobalRKProfiles) != -1);
+}
+
+void
 eGlobalADProfiles_changed_cb(
         GtkComboBox*,
         const gpointer userdata)
diff --git a/upstream/src/aghermann/ui/mw/mw_cb.hh b/upstream/src/aghermann/ui/mw/mw_cb.hh
index 521124b..2ec66c3 100644
--- a/upstream/src/aghermann/ui/mw/mw_cb.hh
+++ b/upstream/src/aghermann/ui/mw/mw_cb.hh
@@ -31,6 +31,7 @@ void iExpSubjectSortAny_toggled_cb( GtkCheckMenuItem*, gpointer);
 void iExpSubjectSortAscending_toggled_cb( GtkCheckMenuItem*, gpointer);
 void iExpSubjectSortSegregate_toggled_cb( GtkCheckMenuItem*, gpointer);
 void iExpBasicSADetectUltradianCycles_activate_cb( GtkMenuItem*, gpointer);
+void iExpGloballyScore_activate_cb( GtkMenuItem*, gpointer);
 void iExpGloballyDetectArtifacts_activate_cb( GtkMenuItem*, gpointer);
 void iExpGloballySetFilters_activate_cb( GtkMenuItem*, gpointer);
 void iExpClose_activate_cb( GtkMenuItem*, gpointer);
@@ -39,6 +40,7 @@ void iExpQuit_activate_cb( GtkMenuItem*, gpointer);
 void iHelpAbout_activate_cb( GtkMenuItem*, gpointer);
 void iHelpUsage_activate_cb( GtkMenuItem*, gpointer);
 
+void eGlobalRKProfiles_changed_cb( GtkComboBox*, gpointer);
 void eGlobalADProfiles_changed_cb( GtkComboBox*, gpointer);
 void bGlobalMontageResetAll_clicked_cb( GtkButton*, gpointer);
 
diff --git a/upstream/src/aghermann/ui/mw/widgets.hh b/upstream/src/aghermann/ui/mw/widgets.hh
index 803d4db..47b734a 100644
--- a/upstream/src/aghermann/ui/mw/widgets.hh
+++ b/upstream/src/aghermann/ui/mw/widgets.hh
@@ -46,6 +46,7 @@ struct SExpDesignUIWidgets {
                 *mSessions,
                 *mEEGChannels,
                 *mAllChannels,
+                *mGlobalRKProfiles,
                 *mGlobalADProfiles;
         GtkTreeStore
                 *mGlobalAnnotations,
@@ -103,6 +104,7 @@ struct SExpDesignUIWidgets {
                 *iiExpGlobalOperations,
                 *iiExpSubjectSort,
                 *iExpGloballyDetectArtifacts,
+                *iExpGloballyScore,
                 *iExpGloballySetFilters,
                 *iMontageSetDefaults,
                 *iHelpAbout,
@@ -321,6 +323,18 @@ struct SExpDesignUIWidgets {
                 *eBatchSetupRangeInc,
                 *eBatchSetupRangeSteps;
 
+        // global score
+        GtkDialog
+                *wGlobalScore;
+        GtkComboBox
+                *eGlobalRKProfiles;
+        GtkCheckButton
+                *eGlobalRKKeepExisting;
+        GtkLabel
+                *lGlobalRKHint;
+        GtkButton
+                *bGlobalRKOK;
+
         // global artifact detection
         GtkDialog
                 *wGlobalArtifactDetection;
diff --git a/upstream/src/libsigfile/page.hh b/upstream/src/libsigfile/page.hh
index 2ca4aa4..67ce0ef 100644
--- a/upstream/src/libsigfile/page.hh
+++ b/upstream/src/libsigfile/page.hh
@@ -129,6 +129,11 @@ struct SPage {
                         mark( char2score(as));
                 }
 
+        void mark( float nrem, float rem, float wake)
+                {
+                        NREM = nrem, REM = rem, Wake = wake;
+                }
+
 
         SPage( float nrem = 0., float rem = 0., float wake = 0.)
               : NREM (nrem), REM (rem), Wake (wake)
@@ -225,6 +230,11 @@ class CHypnogram
         };
         TError save( const string&) const;
         TError load( const string&);
+        void clear()
+                {
+                        for ( auto& P : _pages )
+                                P.mark( 0., 0., 0.);
+                }
 
         int save_canonical( const string& fname) const;
         typedef array<string, (size_t)SPage::TScore::TScore_total> TCustomScoreCodes;

-- 
Alioth's /git/debian-med/git-commit-notice on /srv/git.debian.org/git/debian-med/aghermann.git



More information about the debian-med-commit mailing list