File size: 3,715 Bytes
68ce2fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-    */
/* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */

/*

  Author(s):  Anton Deguet, Ali Uneri
  Created on: 2009-10-26

  (C) Copyright 2009 Johns Hopkins University (JHU), All Rights Reserved.

--- begin cisst license - do not edit ---

This software is provided "as is" under an open source license, with
no warranty.  The complete license can be found in license.txt and
http://www.cisst.org/cisst/license.txt.

--- end cisst license ---
*/

#include "clientQtComponent.h"
#include <cisstMultiTask/mtsInterfaceRequired.h>

CMN_IMPLEMENT_SERVICES(clientQtComponent);


clientQtComponent::clientQtComponent(const std::string & componentName):
    mtsComponent(componentName),
    EventCounter(0)
{
    // create the cisstMultiTask interface with commands and events
    mtsInterfaceRequired * required = AddInterfaceRequired("Required");
    if (required) {
        required->AddFunction("Void", Void);
        required->AddFunction("Write", Write);
        required->AddFunction("Read", Read);
        required->AddFunction("QualifiedRead", QualifiedRead);
        required->AddEventHandlerVoid(&clientQtComponent::EventVoidHandler, this, "EventVoid");
        required->AddEventHandlerWrite(&clientQtComponent::EventWriteHandler, this, "EventWrite");
    }

    // create the user interface
    ClientWidget.setupUi(&CentralWidget);
    MainWindow.setCentralWidget(&CentralWidget);
    MainWindow.setWindowTitle(QString::fromStdString(componentName));
    MainWindow.show();

    // trigger void command
    QObject::connect(ClientWidget.VoidButton, SIGNAL(clicked()),
                     this, SLOT(VoidQSlot()));
    // trigger write command
    QObject::connect(ClientWidget.WriteSlider, SIGNAL(valueChanged(int)),
                     this, SLOT(WriteQSlot(int)));
    QObject::connect(ClientWidget.WriteSlider, SIGNAL(valueChanged(int)),
                     ClientWidget.WriteValue, SLOT(setNum(int)));
    // trigger read command and then refresh the UI
    QObject::connect(ClientWidget.ReadButton, SIGNAL(clicked()),
                     this, SLOT(ReadQSlot()));
    QObject::connect(this, SIGNAL(ReadQSignal(int)),
                     ClientWidget.ReadValue, SLOT(setNum(int)));
    // trigger qualified read command and then refresh the UI
    QObject::connect(ClientWidget.QualifiedReadSlider, SIGNAL(valueChanged(int)),
                     this, SLOT(QualifiedReadQSlot(int)));
    QObject::connect(ClientWidget.QualifiedReadSlider, SIGNAL(valueChanged(int)),
                     ClientWidget.QualifiedReadQualifierValue, SLOT(setNum(int)));
    QObject::connect(this, SIGNAL(QualifiedReadQSignal(int)),
                     ClientWidget.QualifiedReadReadValue, SLOT(setNum(int)));
    // refresh event counter when events are received
    QObject::connect(this, SIGNAL(EventQSignal(int)),
                     ClientWidget.EventValue, SLOT(setNum(int)));
}


void clientQtComponent::EventVoidHandler(void)
{
    EventCounter = 0;
    emit EventQSignal(EventCounter);
}


void clientQtComponent::EventWriteHandler(const mtsInt & value)
{
    EventCounter += value.Data;
    emit EventQSignal(EventCounter);
}


void clientQtComponent::VoidQSlot(void)
{
    Void();
}


void clientQtComponent::WriteQSlot(int newValue)
{
    mtsInt data = newValue;
    Write(data);
}


void clientQtComponent::ReadQSlot(void)
{
    mtsInt data;
    Read(data);
    emit ReadQSignal(data.Data);
}


void clientQtComponent::QualifiedReadQSlot(int newValue)
{
    mtsInt qualifier, data;
    qualifier.Data = newValue;
    QualifiedRead(qualifier, data);
    emit QualifiedReadQSignal(data.Data);
}