Skip to content

Commit

Permalink
Use oms3_setConnectionGeometry instead of oms3_updateConnection
Browse files Browse the repository at this point in the history
Edit the TLM connection using `oms3_setTLMConnectionParameters`
  • Loading branch information
adeas31 authored and lochel committed Nov 6, 2018
1 parent 41d9433 commit 1185761
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 47 deletions.
52 changes: 13 additions & 39 deletions OMEdit/OMEditGUI/Annotations/LineAnnotation.cpp
Expand Up @@ -1058,56 +1058,26 @@ void LineAnnotation::setAligned(bool aligned)
void LineAnnotation::updateOMSConnection()
{
// connection geometry
ssd_connection_geometry_t* pConnectionGeometry = new ssd_connection_geometry_t;
ssd_connection_geometry_t connectionGeometry;
QList<QPointF> points = mPoints;
if (points.size() >= 2) {
points.removeFirst();
points.removeLast();
}
pConnectionGeometry->n = points.size();
connectionGeometry.n = points.size();
if (points.size() == 0) {
pConnectionGeometry->pointsX = NULL;
pConnectionGeometry->pointsY = NULL;
connectionGeometry.pointsX = NULL;
connectionGeometry.pointsY = NULL;
} else {
pConnectionGeometry->pointsX = new double[points.size()];
pConnectionGeometry->pointsY = new double[points.size()];
connectionGeometry.pointsX = new double[points.size()];
connectionGeometry.pointsY = new double[points.size()];
}
for (int i = 0 ; i < points.size() ; i++) {
pConnectionGeometry->pointsX[i] = points.at(i).x();
pConnectionGeometry->pointsY[i] = points.at(i).y();
}
// connection
oms3_connection_t connection;
// connection type
connection.type = getOMSConnectionType();
QString conA = QString("%1.%2").arg(StringHandler::getLastWordAfterDot(StringHandler::removeLastWordAfterDot(getStartComponentName())))
.arg(StringHandler::getLastWordAfterDot(getStartComponentName()));
connection.conA = new char[conA.toStdString().size() + 1];
strcpy(connection.conA, conA.toStdString().c_str());
QString conB = QString("%1.%2").arg(StringHandler::getLastWordAfterDot(StringHandler::removeLastWordAfterDot(getEndComponentName())))
.arg(StringHandler::getLastWordAfterDot(getEndComponentName()));
connection.conB = new char[conB.toStdString().size() + 1];
strcpy(connection.conB, conB.toStdString().c_str());
connection.geometry = pConnectionGeometry;
if (connection.type == oms3_connection_tlm) {
connection.tlmparameters = new oms3_tlm_connection_parameters_t;
connection.tlmparameters->delay = mDelay.toDouble();
connection.tlmparameters->alpha = mAlpha.toDouble();
connection.tlmparameters->linearimpedance = mZf.toDouble();
connection.tlmparameters->angularimpedance = mZfr.toDouble();
} else {
connection.tlmparameters = NULL;
connectionGeometry.pointsX[i] = points.at(i).x();
connectionGeometry.pointsY[i] = points.at(i).y();
}
OMSProxy::instance()->updateConnection(getStartComponentName(), getEndComponentName(), &connection);

delete[] connection.conA;
delete[] connection.conB;
if (connection.tlmparameters) {
delete connection.tlmparameters;
}
delete[] pConnectionGeometry->pointsX;
delete[] pConnectionGeometry->pointsY;
delete pConnectionGeometry;
OMSProxy::instance()->setConnectionGeometry(getStartComponentName(), getEndComponentName(), &connectionGeometry);
}

void LineAnnotation::showOMSConnection()
Expand All @@ -1116,6 +1086,10 @@ void LineAnnotation::showOMSConnection()
&& (mpEndComponent && mpEndComponent->getLibraryTreeItem()->getOMSBusConnector())) {
BusConnectionDialog *pBusConnectionDialog = new BusConnectionDialog(mpGraphicsView, this, false);
pBusConnectionDialog->exec();
} else if ((mpStartComponent && mpStartComponent->getLibraryTreeItem()->getOMSTLMBusConnector())
&& (mpEndComponent && mpEndComponent->getLibraryTreeItem()->getOMSTLMBusConnector())) {
TLMConnectionDialog *pTLMBusConnectionDialog = new TLMConnectionDialog(mpGraphicsView, this, false);
pTLMBusConnectionDialog->exec();
}
}

Expand Down
16 changes: 15 additions & 1 deletion OMEdit/OMEditGUI/Modeling/BusDialog.cpp
Expand Up @@ -1691,7 +1691,21 @@ void TLMConnectionDialog::addTLMConnection()
AddConnectionCommand *pAddConnectionCommand = new AddConnectionCommand(mpConnectionLineAnnotation, true);
mpGraphicsView->getModelWidget()->getUndoStack()->push(pAddConnectionCommand);
} else {
/*! @todo Edit the TLM connection */
oms3_tlm_connection_parameters_t oldTLMParameters;
oldTLMParameters.delay = mpConnectionLineAnnotation->getDelay().toDouble();
oldTLMParameters.alpha = mpConnectionLineAnnotation->getAlpha().toDouble();
oldTLMParameters.linearimpedance = mpConnectionLineAnnotation->getZf().toDouble();
oldTLMParameters.angularimpedance = mpConnectionLineAnnotation->getZfr().toDouble();

oms3_tlm_connection_parameters_t newTLMParameters;
newTLMParameters.delay = mpDelayTextBox->text().toDouble();
newTLMParameters.alpha = mpAlphaTextBox->text().toDouble();
newTLMParameters.linearimpedance = mpLinearImpedanceTextBox->text().toDouble();
newTLMParameters.angularimpedance = mpAngularImpedanceTextBox->text().toDouble();

UpdateTLMParametersCommand *pUpdateTLMParametersCommand = new UpdateTLMParametersCommand(mpConnectionLineAnnotation, oldTLMParameters,
newTLMParameters);
mpGraphicsView->getModelWidget()->getUndoStack()->push(pUpdateTLMParametersCommand);
}
mpGraphicsView->getModelWidget()->updateModelText();
accept();
Expand Down
43 changes: 43 additions & 0 deletions OMEdit/OMEditGUI/Modeling/Commands.cpp
Expand Up @@ -2860,3 +2860,46 @@ void DeleteConnectorFromTLMBusCommand::undo()
mpGraphicsView->getModelWidget()->associateBusWithConnector(StringHandler::getLastWordAfterDot(mTLMBus),
StringHandler::getLastWordAfterDot(mConnectorName));
}

UpdateTLMParametersCommand::UpdateTLMParametersCommand(LineAnnotation *pConnectionLineAnnotation,
const oms3_tlm_connection_parameters_t oldTLMParameters,
const oms3_tlm_connection_parameters_t newTLMParameters, UndoCommand *pParent)
: UndoCommand(pParent)
{
mpConnectionLineAnnotation = pConnectionLineAnnotation;
mOldTLMParameters = oldTLMParameters;
mNewTLMParameters = newTLMParameters;
}

/*!
* \brief UpdateTLMParametersCommand::redoInternal
* redoInternal the UpdateTLMParametersCommand.
*/
void UpdateTLMParametersCommand::redoInternal()
{
if (!OMSProxy::instance()->setTLMConnectionParameters(mpConnectionLineAnnotation->getStartComponentName(),
mpConnectionLineAnnotation->getEndComponentName(), &mNewTLMParameters)) {
setFailed(true);
return;
}

mpConnectionLineAnnotation->setDelay(QString::number(mNewTLMParameters.delay));
mpConnectionLineAnnotation->setAlpha(QString::number(mNewTLMParameters.alpha));
mpConnectionLineAnnotation->setZf(QString::number(mNewTLMParameters.linearimpedance));
mpConnectionLineAnnotation->setZfr(QString::number(mNewTLMParameters.angularimpedance));
}

/*!
* \brief UpdateTLMParametersCommand::undo
* Undo the UpdateTLMParametersCommand.
*/
void UpdateTLMParametersCommand::undo()
{
OMSProxy::instance()->setTLMConnectionParameters(mpConnectionLineAnnotation->getStartComponentName(),
mpConnectionLineAnnotation->getEndComponentName(), &mOldTLMParameters);

mpConnectionLineAnnotation->setDelay(QString::number(mOldTLMParameters.delay));
mpConnectionLineAnnotation->setAlpha(QString::number(mOldTLMParameters.alpha));
mpConnectionLineAnnotation->setZf(QString::number(mOldTLMParameters.linearimpedance));
mpConnectionLineAnnotation->setZfr(QString::number(mOldTLMParameters.angularimpedance));
}
13 changes: 13 additions & 0 deletions OMEdit/OMEditGUI/Modeling/Commands.h
Expand Up @@ -626,4 +626,17 @@ class DeleteConnectorFromTLMBusCommand : public UndoCommand
GraphicsView *mpGraphicsView;
};

class UpdateTLMParametersCommand : public UndoCommand
{
public:
UpdateTLMParametersCommand(LineAnnotation *pConnectionLineAnnotation, const oms3_tlm_connection_parameters_t oldTLMParameters,
const oms3_tlm_connection_parameters_t newTLMParameters, UndoCommand *pParent = 0);
void redoInternal();
void undo();
private:
LineAnnotation *mpConnectionLineAnnotation;
oms3_tlm_connection_parameters_t mOldTLMParameters;
oms3_tlm_connection_parameters_t mNewTLMParameters;
};

#endif // COMMANDS_H
31 changes: 25 additions & 6 deletions OMEdit/OMEditGUI/OMS/OMSProxy.cpp
Expand Up @@ -981,20 +981,39 @@ bool OMSProxy::deleteConnection(QString crefA, QString crefB)
}

/*!
* \brief OMSProxy::updateConnection
* Updates the connection
* \brief OMSProxy::setConnectionGeometry
* Sets the connection geometry.
* \param crefA
* \param crefB
* \param pConnection
* \param pGeometry
* \return
*/
bool OMSProxy::setConnectionGeometry(QString crefA, QString crefB, const ssd_connection_geometry_t *pGeometry)
{
QString command = "oms3_setConnectionGeometry";
QStringList args;
args << crefA << crefB;
LOG_COMMAND(command, args);
oms_status_enu_t status = oms3_setConnectionGeometry(crefA.toStdString().c_str(), crefB.toStdString().c_str(), pGeometry);
logResponse(command, status, &commandTime);
return statusToBool(status);
}

/*!
* \brief OMSProxy::setTLMConnectionParameters
* Sets the TLM parameters of a connection.
* \param crefA
* \param crefB
* \param pParameters
* \return
*/
bool OMSProxy::updateConnection(QString crefA, QString crefB, const oms3_connection_t* pConnection)
bool OMSProxy::setTLMConnectionParameters(QString crefA, QString crefB, const oms3_tlm_connection_parameters_t *pParameters)
{
QString command = "oms3_updateConnection";
QString command = "oms3_setTLMConnectionParameters";
QStringList args;
args << crefA << crefB;
LOG_COMMAND(command, args);
oms_status_enu_t status = oms3_updateConnection(crefA.toStdString().c_str(), crefB.toStdString().c_str(), pConnection);
oms_status_enu_t status = oms3_setTLMConnectionParameters(crefA.toStdString().c_str(), crefB.toStdString().c_str(), pParameters);
logResponse(command, status, &commandTime);
return statusToBool(status);
}
Expand Down
3 changes: 2 additions & 1 deletion OMEdit/OMEditGUI/OMS/OMSProxy.h
Expand Up @@ -109,7 +109,8 @@ class OMSProxy : public QObject
bool addConnection(QString crefA, QString crefB);
bool addTLMConnection(QString crefA, QString crefB, double delay, double alpha, double linearimpedance, double angularimpedance);
bool deleteConnection(QString crefA, QString crefB);
bool updateConnection(QString crefA, QString crefB, const oms3_connection_t *pConnection);
bool setConnectionGeometry(QString crefA, QString crefB, const ssd_connection_geometry_t *pGeometry);
bool setTLMConnectionParameters(QString crefA, QString crefB, const oms3_tlm_connection_parameters_t *pParameters);
bool initialize(QString ident);
bool simulate_asynchronous(QString ident/*, int* terminate*/);
bool reset(QString ident);
Expand Down

0 comments on commit 1185761

Please sign in to comment.