Skip to content

Commit

Permalink
Handle Component modifiers when we do duplicate.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Oct 30, 2015
1 parent 2823f5a commit c790357
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 35 deletions.
45 changes: 13 additions & 32 deletions OMEdit/OMEditGUI/Component/Component.cpp
Expand Up @@ -225,20 +225,6 @@ void ComponentInfo::setArrayIndex(QString arrayIndex)
*/
bool ComponentInfo::operator==(const ComponentInfo &componentInfo) const
{
qDebug() << (componentInfo.getClassName() == this->getClassName());
qDebug() << (componentInfo.getName() == this->getName());
qDebug() << (componentInfo.getComment() == this->getComment());
qDebug() << (componentInfo.getProtected() == this->getProtected());
qDebug() << (componentInfo.getFinal() == this->getFinal());
qDebug() << (componentInfo.getFlow() == this->getFlow());
qDebug() << (componentInfo.getStream() == this->getStream());
qDebug() << (componentInfo.getReplaceable() == this->getReplaceable());
qDebug() << (componentInfo.getVariablity() == this->getVariablity());
qDebug() << (componentInfo.getInner() == this->getInner());
qDebug() << (componentInfo.getOuter() == this->getOuter());
qDebug() << (componentInfo.getCausality() == this->getCausality());
qDebug() << (componentInfo.getArrayIndex() == this->getArrayIndex());

return (componentInfo.getClassName() == this->getClassName()) && (componentInfo.getName() == this->getName()) &&
(componentInfo.getComment() == this->getComment()) && (componentInfo.getProtected() == this->getProtected()) &&
(componentInfo.getFinal() == this->getFinal()) && (componentInfo.getFlow() == this->getFlow()) &&
Expand Down Expand Up @@ -1432,37 +1418,32 @@ void Component::duplicate()
ComponentInfo *pComponentInfo = new ComponentInfo(mpComponentInfo);
pComponentInfo->setName(name);
mpGraphicsView->addComponentToView(name, mpLibraryTreeItem, transformationString, QPointF(0, 0), dialogAnnotation, pComponentInfo, true, true);
// set component attributes for Diagram Layer component.
// set component modifiers and attributes for Diagram Layer component.
Component *pDiagramComponent = mpGraphicsView->getModelWidget()->getDiagramGraphicsView()->getComponentsList().last();
// save the Component modifiers
QString className = mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getNameStructure();
QMap<QString, QString> componentModifiersMap;
QStringList componentModifiersList = pMainWindow->getOMCProxy()->getComponentModifierNames(className, mpComponentInfo->getName());
foreach (QString componentModifier, componentModifiersList) {
QString originalModifierName = QString(mpComponentInfo->getName()).append(".").append(componentModifier);
QString componentModifierValue = pMainWindow->getOMCProxy()->getComponentModifierValue(className, originalModifierName);
componentModifiersMap.insert(componentModifier, componentModifierValue);
}
// save the old ComponentInfo
ComponentInfo oldDiagramComponentInfo(pDiagramComponent->getComponentInfo());
// Create a new ComponentInfo
ComponentInfo newDiagramComponentInfo(mpComponentInfo);
newDiagramComponentInfo.setName(oldDiagramComponentInfo.getName());
UpdateComponentAttributesCommand *pUpdateDiagramComponentAttributesCommand;
pUpdateDiagramComponentAttributesCommand = new UpdateComponentAttributesCommand(pDiagramComponent, oldDiagramComponentInfo,
newDiagramComponentInfo, true);
newDiagramComponentInfo, true, componentModifiersMap);
mpGraphicsView->getModelWidget()->getUndoStack()->push(pUpdateDiagramComponentAttributesCommand);
setSelected(false);
if (mpGraphicsView->getViewType() == StringHandler::Diagram) {
pDiagramComponent->setSelected(true);
}
// if component is connector then set component attributes for Icon Layer component.
if (mpLibraryTreeItem && mpLibraryTreeItem->isConnector()) {
} else {
Component *pIconComponent = mpGraphicsView->getModelWidget()->getIconGraphicsView()->getComponentsList().last();
// save the old ComponentInfo
ComponentInfo oldIconComponentInfo(pIconComponent->getComponentInfo());
// Create a new ComponentInfo
ComponentInfo newIconComponentInfo(mpComponentInfo);
newIconComponentInfo.setName(oldIconComponentInfo.getName());
UpdateComponentAttributesCommand *pUpdateIconComponentAttributesCommand;
pUpdateIconComponentAttributesCommand = new UpdateComponentAttributesCommand(pIconComponent, oldIconComponentInfo,
newIconComponentInfo, true);

mpGraphicsView->getModelWidget()->getUndoStack()->push(pUpdateIconComponentAttributesCommand);
if (mpGraphicsView->getViewType() == StringHandler::Icon) {
pIconComponent->setSelected(true);
}
pIconComponent->setSelected(true);
}
}

Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Component/ComponentProperties.cpp
Expand Up @@ -1063,7 +1063,7 @@ void ComponentAttributes::updateComponentAttributes()
*/
if (oldComponentInfo != newComponentInfo) {
UpdateComponentAttributesCommand *pUpdateComponentAttributesCommand = new UpdateComponentAttributesCommand(mpComponent, oldComponentInfo,
newComponentInfo, false);
newComponentInfo);
pModelWidget->getUndoStack()->push(pUpdateComponentAttributesCommand);
pModelWidget->updateModelicaText();
}
Expand Down
18 changes: 17 additions & 1 deletion OMEdit/OMEditGUI/Modeling/Commands.cpp
Expand Up @@ -312,13 +312,14 @@ void UpdateComponentTransformationsCommand::undo()

UpdateComponentAttributesCommand::UpdateComponentAttributesCommand(Component *pComponent, const ComponentInfo &oldComponentInfo,
const ComponentInfo &newComponentInfo, bool duplicate,
QUndoCommand *pParent)
QMap<QString, QString> componentModifiersMap, QUndoCommand *pParent)
: QUndoCommand(pParent)
{
mpComponent = pComponent;
mOldComponentInfo.updateComponentInfo(&oldComponentInfo);
mNewComponentInfo.updateComponentInfo(&newComponentInfo);
mDuplicate = duplicate;
mComponentModifiersMap = componentModifiersMap;
setText(QString("Update Component %1 Attributes").arg(mpComponent->getName()));
}

Expand Down Expand Up @@ -424,6 +425,21 @@ void UpdateComponentAttributesCommand::redo()
pOMCProxy->printMessagesStringInternal();
}
}
// apply Component modifiers if duplicate case
if (mDuplicate) {
bool modifierValueChanged = false;
QMap<QString, QString>::iterator componentModifier;
for (componentModifier = mComponentModifiersMap.begin(); componentModifier != mComponentModifiersMap.end(); ++componentModifier) {
QString modifierName = QString(mpComponent->getName()).append(".").append(componentModifier.key());
QString modifierValue = componentModifier.value();
if (pOMCProxy->setComponentModifierValue(modelName, modifierName, modifierValue.prepend("="))) {
modifierValueChanged = true;
}
}
if (modifierValueChanged) {
mpComponent->componentParameterHasChanged();
}
}
}

/*!
Expand Down
4 changes: 3 additions & 1 deletion OMEdit/OMEditGUI/Modeling/Commands.h
Expand Up @@ -105,14 +105,16 @@ class UpdateComponentAttributesCommand : public QUndoCommand
{
public:
UpdateComponentAttributesCommand(Component *pComponent, const ComponentInfo &oldComponentInfo, const ComponentInfo &newComponentInfo,
bool duplicate, QUndoCommand *pParent = 0);
bool duplicate = false, QMap<QString, QString> componentModifiersMap = QMap<QString, QString>(),
QUndoCommand *pParent = 0);
void redo();
void undo();
private:
Component *mpComponent;
ComponentInfo mOldComponentInfo;
ComponentInfo mNewComponentInfo;
bool mDuplicate;
QMap<QString, QString> mComponentModifiersMap;
};

class DeleteComponentCommand : public QUndoCommand
Expand Down

0 comments on commit c790357

Please sign in to comment.