Skip to content

Commit

Permalink
Store built-in type component like Real, Boolean etc. in the list of …
Browse files Browse the repository at this point in the history
…components.

Would be very useful when creating Model Browser and Parameters dialog.
Removed the OMC cache command implementation because it was wrong.
  • Loading branch information
adeas31 committed Oct 8, 2015
1 parent 8ef827d commit 96359f8
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 255 deletions.
87 changes: 52 additions & 35 deletions OMEdit/OMEditGUI/Component/Component.cpp
Expand Up @@ -210,8 +210,13 @@ Component::Component(QString name, LibraryTreeItem *pLibraryTreeItem, QString tr
if (mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::TLM) {
// parseAnnotationString(Helper::defaultComponentAnnotationString);
} else {
if (mpLibraryTreeItem->isNonExisting()) {
if (!mpLibraryTreeItem) { // if built in type e.g Real, Boolean etc.
mpDefaultComponentRectangle->setVisible(true);
mpDefaultComponentText->setVisible(true);
mpCoOrdinateSystem = new CoOrdinateSystem;
} else if (mpLibraryTreeItem->isNonExisting()) { // if class is non existing
mpNonExistingComponentLine->setVisible(true);
mpCoOrdinateSystem = new CoOrdinateSystem;
} else {
createClassInheritedShapes();
createClassShapes(mpLibraryTreeItem);
Expand All @@ -221,14 +226,14 @@ Component::Component(QString name, LibraryTreeItem *pLibraryTreeItem, QString tr
mpDefaultComponentRectangle->setVisible(true);
mpDefaultComponentText->setVisible(true);
}
if (mpGraphicsView->getViewType() == StringHandler::Icon) {
mpCoOrdinateSystem = mpLibraryTreeItem->getModelWidget()->getIconGraphicsView()->getCoOrdinateSystem();
} else {
mpCoOrdinateSystem = mpLibraryTreeItem->getModelWidget()->getDiagramGraphicsView()->getCoOrdinateSystem();
}
}
}
// transformation
if (mpGraphicsView->getViewType() == StringHandler::Icon) {
mpCoOrdinateSystem = mpLibraryTreeItem->getModelWidget()->getIconGraphicsView()->getCoOrdinateSystem();
} else {
mpCoOrdinateSystem = mpLibraryTreeItem->getModelWidget()->getDiagramGraphicsView()->getCoOrdinateSystem();
}
mpTransformation = new Transformation(mpGraphicsView->getViewType());
mpTransformation->parseTransformationString(transformation, boundingRect().width(), boundingRect().height());
if (transformation.isEmpty()) {
Expand All @@ -244,9 +249,11 @@ Component::Component(QString name, LibraryTreeItem *pLibraryTreeItem, QString tr
createActions();
mpOriginItem = new OriginItem(this);
createResizerItems();
setToolTip(tr("<b>%1</b> %2").arg(mpLibraryTreeItem->getNameStructure()).arg(mpComponentInfo->getName()));
connect(mpLibraryTreeItem, SIGNAL(loaded(LibraryTreeItem*)), SLOT(handleLoaded()));
connect(mpLibraryTreeItem, SIGNAL(unLoaded(LibraryTreeItem*)), SLOT(handleUnloaded()));
setToolTip(tr("<b>%1</b> %2").arg(mpComponentInfo->getClassName()).arg(mpComponentInfo->getName()));
if (mpLibraryTreeItem) {
connect(mpLibraryTreeItem, SIGNAL(loaded(LibraryTreeItem*)), SLOT(handleLoaded()));
connect(mpLibraryTreeItem, SIGNAL(unLoaded(LibraryTreeItem*)), SLOT(handleUnloaded()));
}
connect(this, SIGNAL(transformHasChanged()), SLOT(updatePlacementAnnotation()));
connect(this, SIGNAL(transformHasChanged()), SLOT(updateOriginItem()));
}
Expand All @@ -270,7 +277,7 @@ Component::Component(Component *pComponent, GraphicsView *pGraphicsView, Compone
mpTransformation = new Transformation(mpReferenceComponent->getTransformation());
setTransform(mpTransformation->getTransformationMatrix());
mpOriginItem = 0;
setToolTip(tr("<b>%1</b> %2<br /><br />Component declared in %3").arg(mpLibraryTreeItem->getNameStructure()).arg(mpComponentInfo->getName())
setToolTip(tr("<b>%1</b> %2<br /><br />Component declared in %3").arg(mpComponentInfo->getClassName()).arg(mpComponentInfo->getName())
.arg(mpReferenceComponent->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->getNameStructure()));
connect(mpReferenceComponent, SIGNAL(added()), SLOT(referenceComponentAdded()));
connect(mpReferenceComponent, SIGNAL(transformHasChanged()), SLOT(referenceComponentChanged()));
Expand Down Expand Up @@ -304,9 +311,12 @@ Component::Component(Component *pComponent, GraphicsView *pGraphicsView)
if (mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::TLM) {
// parseAnnotationString(Helper::defaultComponentAnnotationString);
} else {
if (mpLibraryTreeItem->isNonExisting()) {
if (!mpLibraryTreeItem) { // if built in type e.g Real, Boolean etc.
mpDefaultComponentRectangle->setVisible(true);
mpDefaultComponentText->setVisible(true);
mpCoOrdinateSystem = new CoOrdinateSystem;
} else if (mpLibraryTreeItem->isNonExisting()) { // if class is non existing
mpNonExistingComponentLine->setVisible(true);
// transformation
mpCoOrdinateSystem = new CoOrdinateSystem;
} else {
createClassInheritedShapes();
Expand All @@ -317,7 +327,6 @@ Component::Component(Component *pComponent, GraphicsView *pGraphicsView)
mpDefaultComponentRectangle->setVisible(true);
mpDefaultComponentText->setVisible(true);
}
// transformation
if (mpGraphicsView->getViewType() == StringHandler::Icon) {
mpCoOrdinateSystem = mpLibraryTreeItem->getModelWidget()->getIconGraphicsView()->getCoOrdinateSystem();
} else {
Expand All @@ -332,10 +341,12 @@ Component::Component(Component *pComponent, GraphicsView *pGraphicsView)
mpGraphicsView->addItem(mpOriginItem);
createResizerItems();
mpGraphicsView->addItem(this);
setToolTip(tr("<b>%1</b> %2<br /><br />Component declared in %3").arg(mpLibraryTreeItem->getNameStructure()).arg(mpComponentInfo->getName())
setToolTip(tr("<b>%1</b> %2<br /><br />Component declared in %3").arg(mpComponentInfo->getClassName()).arg(mpComponentInfo->getName())
.arg(mpReferenceComponent->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->getNameStructure()));
connect(mpLibraryTreeItem, SIGNAL(loaded(LibraryTreeItem*)), SLOT(handleLoaded()));
connect(mpLibraryTreeItem, SIGNAL(unLoaded(LibraryTreeItem*)), SLOT(handleUnloaded()));
if (mpLibraryTreeItem) {
connect(mpLibraryTreeItem, SIGNAL(loaded(LibraryTreeItem*)), SLOT(handleLoaded()));
connect(mpLibraryTreeItem, SIGNAL(unLoaded(LibraryTreeItem*)), SLOT(handleUnloaded()));
}
connect(mpReferenceComponent, SIGNAL(added()), SLOT(referenceComponentAdded()));
connect(mpReferenceComponent, SIGNAL(transformHasChanged()), SLOT(referenceComponentChanged()));
connect(mpReferenceComponent, SIGNAL(transformHasChanged()), SLOT(updateOriginItem()));
Expand Down Expand Up @@ -662,7 +673,7 @@ QString Component::getPlacementAnnotation()
if (mpTransformation) {
placementAnnotationString.append("visible=").append(mpTransformation->getVisible() ? "true" : "false");
}
if (mpLibraryTreeItem->getRestriction() == StringHandler::Connector) {
if (mpLibraryTreeItem && mpLibraryTreeItem->getRestriction() == StringHandler::Connector) {
if (mpGraphicsView->getViewType() == StringHandler::Icon) {
// first get the component from diagram view and get the transformations
Component *pComponent;
Expand Down Expand Up @@ -753,11 +764,11 @@ void Component::emitDeleted()
void Component::componentNameHasChanged()
{
if (mIsInheritedComponent || mComponentType == Component::Port) {
setToolTip(tr("<b>%1</b> %2<br /><br />Component declared in %3").arg(mpLibraryTreeItem->getNameStructure())
setToolTip(tr("<b>%1</b> %2<br /><br />Component declared in %3").arg(mpComponentInfo->getClassName())
.arg(mpComponentInfo->getName())
.arg(mpReferenceComponent->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->getNameStructure()));
} else {
setToolTip(tr("<b>%1</b> %2").arg(mpLibraryTreeItem->getNameStructure()).arg(mpComponentInfo->getName()));
setToolTip(tr("<b>%1</b> %2").arg(mpComponentInfo->getClassName()).arg(mpComponentInfo->getName()));
}
emit displayTextChanged();
}
Expand Down Expand Up @@ -788,27 +799,29 @@ QString Component::getParameterDisplayString(QString parameterName)
displayString = pOMCProxy->getComponentModifierValue(modelName, mpComponentInfo->getName() + "." + parameterName);
/* case 2 */
if (displayString.isEmpty()) {
QList<ComponentInfo*> componentInfoList = pOMCProxy->getComponents(mpLibraryTreeItem->getNameStructure());
foreach (ComponentInfo *pComponentInfo, componentInfoList) {
if (pComponentInfo->getName().compare(parameterName) == 0) {
displayString = pOMCProxy->getParameterValue(mpLibraryTreeItem->getNameStructure(), parameterName);
break;
if (mpLibraryTreeItem) {
foreach (Component *pComponent, mpLibraryTreeItem->getModelWidget()->getDiagramGraphicsView()->getComponentsList()) {
if (pComponent->getComponentInfo()->getName().compare(parameterName) == 0) {
displayString = pOMCProxy->getParameterValue(mpLibraryTreeItem->getNameStructure(), parameterName);
break;
}
}
}
}
/* case 3 */
if (displayString.isEmpty()) {
foreach (Component *pInheritedComponent, mInheritanceList) {
QList<ComponentInfo*> componentInfoList = pOMCProxy->getComponents(pInheritedComponent->getLibraryTreeItem()->getNameStructure());
foreach (ComponentInfo *pComponentInfo, componentInfoList) {
if (pComponentInfo->getName().compare(parameterName) == 0) {
displayString = pOMCProxy->getExtendsModifierValue(mpLibraryTreeItem->getNameStructure(),
pInheritedComponent->getLibraryTreeItem()->getNameStructure(), parameterName);
/* case 3.3 */
if (displayString.isEmpty()) {
displayString = pOMCProxy->getParameterValue(pInheritedComponent->getLibraryTreeItem()->getNameStructure(), parameterName);
if (mpLibraryTreeItem) {
foreach (ModelWidget::InheritedClass *pInheritedClass, mpLibraryTreeItem->getModelWidget()->getInheritedClassesList()) {
foreach (Component *pComponent, pInheritedClass->mpLibraryTreeItem->getModelWidget()->getDiagramGraphicsView()->getComponentsList()) {
if (pComponent->getComponentInfo()->getName().compare(parameterName) == 0) {
displayString = pOMCProxy->getExtendsModifierValue(mpLibraryTreeItem->getNameStructure(),
pInheritedClass->mpLibraryTreeItem->getNameStructure(), parameterName);
/* case 3.3 */
if (displayString.isEmpty()) {
displayString = pOMCProxy->getParameterValue(pInheritedClass->mpLibraryTreeItem->getNameStructure(), parameterName);
}
break;
}
break;
}
}
}
Expand Down Expand Up @@ -947,7 +960,7 @@ void Component::updatePlacementAnnotation()
QString::number(getTransformation()->getRotateAngle()));
} else {
OMCProxy *pOMCProxy = mpGraphicsView->getModelWidget()->getModelWidgetContainer()->getMainWindow()->getOMCProxy();
pOMCProxy->updateComponent(mpComponentInfo->getName(), mpLibraryTreeItem->getNameStructure(),
pOMCProxy->updateComponent(mpComponentInfo->getName(), mpComponentInfo->getClassName(),
mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getNameStructure(), getPlacementAnnotation());
mpGraphicsView->getModelWidget()->updateModelicaText();
}
Expand Down Expand Up @@ -1591,6 +1604,10 @@ void Component::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)

void Component::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
// if user right clicks the built in type like Integer, Real etc. we don't show the context menu.
if (!mpLibraryTreeItem) {
return;
}
Component *pComponent = getRootParentComponent();
if (pComponent->isSelected()) {
pComponent->showResizerItems();
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Component/Transformation.cpp
Expand Up @@ -44,7 +44,7 @@ Transformation::Transformation(StringHandler::ViewType viewType, QObject *pParen
mViewType = viewType;
mWidth = 200.0;
mHeight = 200.0;
mVisible = true;
mVisible = false;
mOriginDiagram = QPointF(0.0, 0.0);
mHasOriginDiagramX = true;
mHasOriginDiagramY = true;
Expand Down
13 changes: 8 additions & 5 deletions OMEdit/OMEditGUI/Modeling/Commands.cpp
Expand Up @@ -50,7 +50,8 @@ AddComponentCommand::AddComponentCommand(QString name, LibraryTreeItem *pLibrary

ModelWidget *pModelWidget = mpGraphicsView->getModelWidget();
// if component is of connector type && containing class is Modelica type.
if (mpLibraryTreeItem->getRestriction() == StringHandler::Connector && pModelWidget->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::Modelica) {
if (mpLibraryTreeItem && mpLibraryTreeItem->getRestriction() == StringHandler::Connector &&
pModelWidget->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::Modelica) {
// first create the component for Icon View
mpIconComponent = new Component(name, pLibraryTreeItem, transformationString, position, pComponentInfo, mpIconGraphicsView);
pModelWidget->getLibraryTreeItem()->emitComponentAdded(mpIconComponent, mpIconGraphicsView);
Expand Down Expand Up @@ -82,7 +83,8 @@ void AddComponentCommand::redo()
{
ModelWidget *pModelWidget = mpGraphicsView->getModelWidget();
// if component is of connector type && containing class is Modelica type.
if (mpLibraryTreeItem->getRestriction() == StringHandler::Connector && pModelWidget->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::Modelica) {
if (mpLibraryTreeItem && mpLibraryTreeItem->getRestriction() == StringHandler::Connector &&
pModelWidget->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::Modelica) {
// first create the component for Icon View only if connector is not protected
if (!mpComponentInfo->getProtected()) {
mpIconGraphicsView->addItem(mpIconComponent);
Expand Down Expand Up @@ -114,7 +116,8 @@ void AddComponentCommand::undo()
{
ModelWidget *pModelWidget = mpGraphicsView->getModelWidget();
// if component is of connector type && containing class is Modelica type.
if (mpLibraryTreeItem->getRestriction() == StringHandler::Connector && pModelWidget->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::Modelica) {
if (mpLibraryTreeItem && mpLibraryTreeItem->getRestriction() == StringHandler::Connector &&
pModelWidget->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::Modelica) {
// first create the component for Icon View only if connector is not protected
if (!mpComponentInfo->getProtected()) {
mpIconComponent->setSelected(false);
Expand Down Expand Up @@ -159,7 +162,7 @@ void DeleteComponentCommand::redo()
{
ModelWidget *pModelWidget = mpGraphicsView->getModelWidget();
// if component is of connector type && containing class is Modelica type.
if (mpComponent->getLibraryTreeItem()->getRestriction() == StringHandler::Connector &&
if (mpComponent->getLibraryTreeItem() && mpComponent->getLibraryTreeItem()->getRestriction() == StringHandler::Connector &&
pModelWidget->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::Modelica) {
// first remove the component from Icon View
mpIconComponent = mpIconGraphicsView->getComponentObject(mpComponent->getName());
Expand Down Expand Up @@ -197,7 +200,7 @@ void DeleteComponentCommand::undo()
{
ModelWidget *pModelWidget = mpGraphicsView->getModelWidget();
// if component is of connector type && containing class is Modelica type.
if (mpComponent->getLibraryTreeItem()->getRestriction() == StringHandler::Connector &&
if (mpComponent->getLibraryTreeItem() && mpComponent->getLibraryTreeItem()->getRestriction() == StringHandler::Connector &&
pModelWidget->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::Modelica) {
// first add the component to Icon View
if (mpIconComponent) {
Expand Down
9 changes: 4 additions & 5 deletions OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp
Expand Up @@ -1062,6 +1062,7 @@ LibraryTreeItem* LibraryTreeModel::createLibraryTreeItem(QString name, LibraryTr
LibraryTreeItem *pLibraryTreeItem = findNonExistingLibraryTreeItem(nameStructure);
if (pLibraryTreeItem && pLibraryTreeItem->isNonExisting()) {
wasNonExisting = true;
pLibraryTreeItem->setSystemLibrary(pParentLibraryTreeItem == mpRootLibraryTreeItem ? isSystemLibrary : pParentLibraryTreeItem->isSystemLibrary());
createNonExistingLibraryTreeItem(pLibraryTreeItem, pParentLibraryTreeItem);
// read the LibraryTreeItem text
readLibraryTreeItemClassText(pLibraryTreeItem);
Expand Down Expand Up @@ -1177,7 +1178,7 @@ void LibraryTreeModel::createNonExistingLibraryTreeItem(LibraryTreeItem *pLibrar
OMCProxy *pOMCProxy = mpLibraryWidget->getMainWindow()->getOMCProxy();
pLibraryTreeItem->setClassInformation(pOMCProxy->getClassInformation(pLibraryTreeItem->getNameStructure()));
pLibraryTreeItem->setIsSaved(isSaved);
pLibraryTreeItem->setSystemLibrary(pParentLibraryTreeItem->isSystemLibrary());
pLibraryTreeItem->setSystemLibrary(pParentLibraryTreeItem == mpRootLibraryTreeItem ? true : pParentLibraryTreeItem->isSystemLibrary());
pLibraryTreeItem->setIsProtected(pOMCProxy->isProtectedClass(pParentLibraryTreeItem->getNameStructure(), pLibraryTreeItem->getName()));
if (pParentLibraryTreeItem->isDocumentationClass()) {
pLibraryTreeItem->setIsDocumentationClass(true);
Expand Down Expand Up @@ -1475,7 +1476,7 @@ LibraryTreeItem* LibraryTreeModel::getLibraryTreeItemFromFile(QString fileName,
* \param text
* \param show
*/
void LibraryTreeModel::showModelWidget(LibraryTreeItem *pLibraryTreeItem, QString text, bool show)
void LibraryTreeModel::showModelWidget(LibraryTreeItem *pLibraryTreeItem, QString text, bool show, bool newModel)
{
QApplication::setOverrideCursor(Qt::WaitCursor);
if (show) {
Expand All @@ -1494,7 +1495,7 @@ void LibraryTreeModel::showModelWidget(LibraryTreeItem *pLibraryTreeItem, QStrin
pLibraryTreeItem->getModelWidget()->hide();
}
} else {
ModelWidget *pModelWidget = new ModelWidget(pLibraryTreeItem, mpLibraryWidget->getMainWindow()->getModelWidgetContainer(), text);
ModelWidget *pModelWidget = new ModelWidget(pLibraryTreeItem, mpLibraryWidget->getMainWindow()->getModelWidgetContainer(), text, newModel);
pLibraryTreeItem->setModelWidget(pModelWidget);
pLibraryTreeItem->getModelWidget()->setWindowTitle(pLibraryTreeItem->getNameStructure() + (pLibraryTreeItem->isSaved() ? "" : "*"));
if (show) {
Expand Down Expand Up @@ -1712,8 +1713,6 @@ void LibraryTreeModel::unloadClassHelper(LibraryTreeItem *pLibraryTreeItem, Libr
int row = pLibraryTreeItem->row();
beginRemoveRows(libraryTreeItemIndex(pLibraryTreeItem), row, row);
pParentLibraryTreeItem->removeChild(pLibraryTreeItem);
// remove all cached OMC commands for LibraryTreeItem
mpLibraryWidget->getMainWindow()->getOMCProxy()->removeCachedOMCCommand(pLibraryTreeItem->getNameStructure());
endRemoveRows();
}

Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.h
Expand Up @@ -234,7 +234,7 @@ class LibraryTreeModel : public QAbstractItemModel
void loadLibraryTreeItemPixmap(LibraryTreeItem *pLibraryTreeItem);
void loadDependentLibraries(QStringList libraries);
LibraryTreeItem* getLibraryTreeItemFromFile(QString fileName, int lineNumber);
void showModelWidget(LibraryTreeItem *pLibraryTreeItem, QString text = QString(""), bool show = true);
void showModelWidget(LibraryTreeItem *pLibraryTreeItem, QString text = QString(""), bool show = true, bool newModel = false);
void showHideProtectedClasses();
bool unloadClass(LibraryTreeItem *pLibraryTreeItem, bool askQuestion = true);
bool unloadTLMOrTextFile(LibraryTreeItem *pLibraryTreeItem, bool askQuestion = true);
Expand Down

0 comments on commit 96359f8

Please sign in to comment.