Skip to content

Commit

Permalink
Some fixes when duplicating components of built-in types.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Oct 26, 2015
1 parent 2176a3c commit e2bbf67
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/Annotations/TextAnnotation.cpp
Expand Up @@ -206,6 +206,8 @@ void TextAnnotation::paint(QPainter *painter, const QStyleOptionGraphicsItem *op
if (mOriginalTextString.contains("%")) {
return;
}
} else if (mpComponent && mpComponent->getGraphicsView()->isRenderingLibraryPixmap()) {
return;
}
if (mVisible) {
drawTextAnnotaion(painter);
Expand Down
26 changes: 16 additions & 10 deletions OMEdit/OMEditGUI/Component/Component.cpp
Expand Up @@ -1294,24 +1294,30 @@ void Component::deleteMe()
void Component::duplicate()
{
MainWindow *pMainWindow = mpGraphicsView->getModelWidget()->getModelWidgetContainer()->getMainWindow();
// get the model defaultComponentName
QString defaultName = pMainWindow->getOMCProxy()->getDefaultComponentName(mpLibraryTreeItem->getNameStructure());
QString name;
if (defaultName.isEmpty()) {
name = mpGraphicsView->getUniqueComponentName(StringHandler::toCamelCase(mpLibraryTreeItem->getName()));
} else {
if (mpGraphicsView->checkComponentName(defaultName)) {
name = defaultName;
if (mpLibraryTreeItem) {
// get the model defaultComponentName
QString defaultName = pMainWindow->getOMCProxy()->getDefaultComponentName(mpLibraryTreeItem->getNameStructure());
if (defaultName.isEmpty()) {
name = mpGraphicsView->getUniqueComponentName(StringHandler::toCamelCase(mpLibraryTreeItem->getName()));
} else {
name = mpGraphicsView->getUniqueComponentName(defaultName);
if (mpGraphicsView->checkComponentName(defaultName)) {
name = defaultName;
} else {
name = mpGraphicsView->getUniqueComponentName(defaultName);
}
}
} else {
name = mpGraphicsView->getUniqueComponentName(StringHandler::toCamelCase(getName()));
}
QPointF gridStep(mpGraphicsView->getCoOrdinateSystem()->getHorizontalGridStep() * 5,
mpGraphicsView->getCoOrdinateSystem()->getVerticalGridStep() * 5);
QString transformationString = getOMCPlacementAnnotation(gridStep);

// add component
mpGraphicsView->addComponentToView(name, mpLibraryTreeItem, transformationString, QPointF(0, 0), new ComponentInfo(), true, true);
ComponentInfo *pComponentInfo = new ComponentInfo(mpComponentInfo);
pComponentInfo->setName(name);
mpGraphicsView->addComponentToView(name, mpLibraryTreeItem, transformationString, QPointF(0, 0), pComponentInfo, true, true);
// set component attributes for Diagram Layer component.
Component *pDiagramComponent = mpGraphicsView->getModelWidget()->getDiagramGraphicsView()->getComponentsList().last();
// save the old ComponentInfo
Expand All @@ -1328,7 +1334,7 @@ void Component::duplicate()
pDiagramComponent->setSelected(true);
}
// if component is connector then set component attributes for Icon Layer component.
if (mpLibraryTreeItem->isConnector()) {
if (mpLibraryTreeItem && mpLibraryTreeItem->isConnector()) {
Component *pIconComponent = mpGraphicsView->getModelWidget()->getIconGraphicsView()->getComponentsList().last();
// save the old ComponentInfo
ComponentInfo oldIconComponentInfo(pIconComponent->getComponentInfo());
Expand Down
9 changes: 7 additions & 2 deletions OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -389,8 +389,13 @@ void GraphicsView::addComponentToClass(Component *pComponent)
if (mpModelWidget->getLibraryTreeItem()->getLibraryType()== LibraryTreeItem::Modelica) {
MainWindow *pMainWindow = mpModelWidget->getModelWidgetContainer()->getMainWindow();
// Add the component to model in OMC Global Scope.
QString className = StringHandler::makeClassNameRelative(pComponent->getLibraryTreeItem()->getNameStructure(),
mpModelWidget->getLibraryTreeItem()->getNameStructure());
QString className;
if (pComponent->getLibraryTreeItem()) {
className = StringHandler::makeClassNameRelative(pComponent->getLibraryTreeItem()->getNameStructure(),
mpModelWidget->getLibraryTreeItem()->getNameStructure());
} else {
className = pComponent->getComponentInfo()->getClassName();
}
pMainWindow->getOMCProxy()->addComponent(pComponent->getName(), className, mpModelWidget->getLibraryTreeItem()->getNameStructure(),
pComponent->getPlacementAnnotation());
} else if (mpModelWidget->getLibraryTreeItem()->getLibraryType()== LibraryTreeItem::TLM) {
Expand Down

0 comments on commit e2bbf67

Please sign in to comment.