7 #include "fwGui/view/IActivityView.hpp" 9 #include "fwGui/dialog/MessageDialog.hpp" 11 #include <fwActivities/IActivityValidator.hpp> 12 #include <fwActivities/IValidator.hpp> 14 #include <fwCom/Slot.hpp> 15 #include <fwCom/Slot.hxx> 16 #include <fwCom/Slots.hxx> 18 #include <fwData/Composite.hpp> 19 #include <fwData/String.hpp> 21 #include <fwDataCamp/getObject.hpp> 23 #include <fwRuntime/operations.hpp> 25 #include <fwServices/macros.hpp> 27 #include <fwTools/dateAndTime.hpp> 28 #include <fwTools/UUID.hpp> 35 const ::fwCom::Slots::SlotKeyType IActivityView::s_LAUNCH_ACTIVITY_SLOT =
"launchActivity";
36 const ::fwCom::Slots::SlotKeyType IActivityView::s_LAUNCH_ACTIVITY_SERIES_SLOT =
"launchActivitySeries";
63 const auto inoutsCfg = config.equal_range(
"inout");
64 for (
auto itCfg = inoutsCfg.first; itCfg != inoutsCfg.second; ++itCfg)
66 const std::string key = itCfg->second.get<std::string>(
"<xmlattr>.key");
67 SLM_ASSERT(
"Missing 'key' tag.", !key.empty());
69 const std::string uid = itCfg->second.get<std::string>(
"<xmlattr>.uid");
70 SLM_ASSERT(
"Missing 'uid' tag.", !uid.empty());
72 const std::string strOptional = itCfg->second.get<std::string>(
"<xmlattr>.optional",
"no");
73 const bool optional = (strOptional ==
"yes");
75 ::fwData::Object::csptr obj = this->getInOut< ::fwData::Object>(key);
84 SLM_ASSERT(
"Object key '" + key +
"'with uid '" + uid +
"' does not exists.", obj);
85 param.by = obj->getID();
90 ConfigType configParams = config.get_child(
"parameters");
92 const auto paramsCfg = configParams.equal_range(
"parameter");
93 for (
auto itParams = paramsCfg.first; itParams != paramsCfg.second; ++itParams)
95 const std::string replace = itParams->second.get<std::string>(
"<xmlattr>.replace");
96 std::string by = itParams->second.get<std::string>(
"<xmlattr>.by",
"");
99 by = itParams->second.get<std::string>(
"<xmlattr>.uid");
101 SLM_ASSERT(
"'parameter' tag must contain valid 'replace' and 'by' attributes.",
102 !replace.empty() && !by.empty());
104 param.replace = replace;
106 SLM_ASSERT(
"'camp' paths are not managed in the configuration parameters", !param.isSeshat());
115 ::fwMedData::ActivitySeries::sptr activitySeries = ::fwMedData::ActivitySeries::dynamicCast(series);
132 std::shared_ptr< ::fwRuntime::Bundle > bundle = ::fwRuntime::findBundle(info.
bundleId, info.
bundleVersion);
133 if (!bundle->isStarted())
141 ::fwActivities::IValidator::sptr validator = ::fwActivities::validator::factory::New(validatorImpl);
143 ::fwActivities::IActivityValidator::sptr activityValidator =
144 ::fwActivities::IActivityValidator::dynamicCast(validator);
145 SLM_ASSERT(
"Validator '" + validatorImpl +
"' instantiation failed", activityValidator);
148 if(!validation.first)
150 const std::string message =
"The activity '" + info.title +
"' can not be launched:\n" + validation.second;
153 ::fwGui::dialog::IMessageDialog::CRITICAL);
169 ::fwMedData::ActivitySeries::sptr actSeries = ::fwMedData::ActivitySeries::New();
170 if (info.requirements.size() > 0)
172 ::fwData::Composite::sptr data = actSeries->getData();
177 (*data)[req.name] = ::fwData::factory::New(req.
type);
184 "This activity needs parameters that cannot be defined",
185 ::fwGui::dialog::IMessageDialog::INFO);
191 actSeries->setModality(
"OT");
194 const ::boost::posix_time::ptime now = ::boost::posix_time::second_clock::local_time();
197 actSeries->setActivityConfigId(info.id);
205 ReplaceMapType& replaceMap )
207 for(
const ParametersType::value_type& param : parameters)
209 if(!param.isSeshat())
211 replaceMap[param.replace] = param.by;
215 std::string parameterToReplace = param.by;
216 if (parameterToReplace.substr(0, 1) ==
"!")
218 parameterToReplace.replace(0, 1,
"@");
221 ::fwData::Object::sptr obj = ::fwDataCamp::getObject(sourceObj, parameterToReplace);
222 SLM_ASSERT(
"Invalid seshat path : '" + param.by +
"'", obj);
224 ::fwData::String::sptr stringParameter = ::fwData::String::dynamicCast(obj);
226 std::string parameterValue = obj->getID();
228 if(stringParameter && param.by.substr(0, 1) ==
"!")
230 parameterValue = stringParameter->getValue();
232 replaceMap[param.replace] = parameterValue;
241 for(
const ParametersType::value_type& param : parameters)
243 replaceMap[param.replace] = param.by;
virtual FWGUI_API void launchActivitySeries(::fwMedData::Series::sptr series)
Slot: Launch the given activity in a new tab.
std::pair< bool, std::string > ValidationType
Defines validation result of an activity. First element tells if the activity is validated or not by ...
Holds Activities configuration.
The namespace fwGui contains the base interface for IHM services.
#define SLM_DEBUG_IF(message, cond)
unsigned int maxOccurs
minimum number of data required
static FWGUI_API IMessageDialog::Buttons showMessageDialog(const std::string &title, const std::string &message,::fwGui::dialog::IMessageDialog::Icons icon=INFO)
static FWACTIVITIES_API Activities::sptr getDefault()
Return the default global instance of Activities.
std::string m_mainActivityId
configuration id of the main activity
std::string bundleVersion
Version of the bundle containing the activity.
ParametersType m_parameters
parameters given in configuration
std::string type
parameter name
virtual FWGUI_API bool validateActivity(::fwMedData::ActivitySeries::sptr activitySeries) const
Check if the activity is valid by calling the activity validator.
std::string bundleId
Identifier of the bundle containing the activity.
virtual FWGUI_API::fwMedData::ActivitySeries::sptr createMainActivity() const
Create the activity series given in 'mainActivity' configuration.
unsigned int minOccurs
Implementation of data validator.
virtual FWGUI_API ~IActivityView()
Destructor. Do nothing.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
virtual FWGUI_API void configuring() override
Parse the configuration.
FWGUI_API IActivityView()
Constructor. Do nothing.
std::vector< std::string > validatorsImpl
Validator implementations.
bool create
maximum number of data required
virtual FWGUI_API void translateParameters(::fwData::Object::sptr sourceObj, const ParametersType ¶meters, ReplaceMapType &replaceMap)
Translate parameters from source object.
virtual FWGUI_API void launchActivity(::fwMedData::ActivitySeries::sptr activitySeries)=0
Slot: Launch the given activity in a new tab.
FWGUI_API void initialize()
Initialize managers.
virtual FWSERVICES_API void info(std::ostream &_sstream)
Write information in a stream.
FWSERVICES_API ConfigType getConfigTree() const
Return the configuration, in an boost property tree.