Ignore:
Timestamp:
2012-10-20T20:27:24+02:00 (12 years ago)
Author:
adeas31
Message:
  • Removed some old classes.
  • Better connection support for array type connectors.
  • Don't call getClassNames every time for searching of Modelica classes.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/OMEdit/OMEditGUI/Component.cpp

    r13474 r13537  
    3636#include "Component.h"
    3737
    38 Component_OMC::Component_OMC(QString annotation, QString name, QString className, StringHandler::ModelicaClasses type, QString transformation,
    39                              QPointF position, OMCProxy *pOMCProxy, GraphicsView *pGraphicsView, Component_OMC *pParent)
     38Component::Component(QString annotation, QString name, QString className, StringHandler::ModelicaClasses type, QString transformation,
     39                             QPointF position, OMCProxy *pOMCProxy, GraphicsView *pGraphicsView, Component *pParent)
    4040  : QGraphicsItem(pParent), mName(name), mClassName(className), mType(type), mpOMCProxy(pOMCProxy), mpGraphicsView(pGraphicsView),
    4141    mpParentComponent(pParent)
     
    6767  // if type is connector and component is not a library component.
    6868  if (mType == StringHandler::CONNECTOR && !isLibraryComponent())
    69     connect(this, SIGNAL(componentClicked(Component_OMC*)), mpGraphicsView, SLOT(addConnection(Component_OMC*)));
     69    connect(this, SIGNAL(componentClicked(Component*)), mpGraphicsView, SLOT(addConnection(Component*)));
    7070}
    7171
    7272/* Called for inheritance annotation instance */
    73 Component_OMC::Component_OMC(QString annotation, QString className, StringHandler::ModelicaClasses type, Component_OMC *pParent)
     73Component::Component(QString annotation, QString className, StringHandler::ModelicaClasses type, Component *pParent)
    7474  : QGraphicsItem(pParent), mName(""), mClassName(className), mType(type), mpParentComponent(pParent)
    7575{
     
    8585  // if type is connector and component is not a library component.
    8686  if (mType == StringHandler::CONNECTOR && !isLibraryComponent() && mpParentComponent->getType() != StringHandler::CONNECTOR)
    87     connect(this, SIGNAL(componentClicked(Component_OMC*)), mpGraphicsView, SLOT(addConnection(Component_OMC*)));
     87    connect(this, SIGNAL(componentClicked(Component*)), mpGraphicsView, SLOT(addConnection(Component*)));
    8888}
    8989
    9090/* Called for component annotation instance */
    91 Component_OMC::Component_OMC(QString annotation, QString transformationString, ComponentInfo *pComponentInfo,
    92                              StringHandler::ModelicaClasses type, Component_OMC *pParent)
     91Component::Component(QString annotation, QString transformationString, ComponentInfo *pComponentInfo,
     92                             StringHandler::ModelicaClasses type, Component *pParent)
    9393  : QGraphicsItem(pParent), mpComponentInfo(pComponentInfo), mType(type), mpParentComponent(pParent)
    9494{
     
    107107  // if type is connector and component is not a library component.
    108108  if (mType == StringHandler::CONNECTOR && !isLibraryComponent() && mpParentComponent->getType() != StringHandler::CONNECTOR)
    109     connect(this, SIGNAL(componentClicked(Component_OMC*)), mpGraphicsView, SLOT(addConnection(Component_OMC*)));
     109    connect(this, SIGNAL(componentClicked(Component*)), mpGraphicsView, SLOT(addConnection(Component*)));
    110110}
    111111
    112112/* Used for Library Component */
    113 Component_OMC::Component_OMC(QString annotation, QString className, OMCProxy *pOMCProxy, Component_OMC *pParent)
     113Component::Component(QString annotation, QString className, OMCProxy *pOMCProxy, Component *pParent)
    114114  : QGraphicsItem(pParent), mName(className), mClassName(className), mpParentComponent(pParent)
    115115{
     
    127127}
    128128
    129 void Component_OMC::initialize()
     129void Component::initialize()
    130130{
    131131  mVisible = true;
     
    163163}
    164164
    165 bool Component_OMC::isLibraryComponent()
     165bool Component::isLibraryComponent()
    166166{
    167167  return mIsLibraryComponent;
    168168}
    169169
    170 void Component_OMC::getClassInheritedComponents(bool isRootComponent)
     170void Component::getClassInheritedComponents(bool isRootComponent)
    171171{
    172172  // read the component inheritance
     
    191191    else
    192192      annotationString = mpOMCProxy->getIconAnnotation(inheritedClass);
    193     Component_OMC *pInheritedComponent;
    194     pInheritedComponent  = new Component_OMC(annotationString, inheritedClass, isConnector, this);
     193    Component *pInheritedComponent;
     194    pInheritedComponent  = new Component(annotationString, inheritedClass, isConnector, this);
    195195    mpInheritanceList.append(pInheritedComponent);
    196196  }
    197197}
    198198
    199 void Component_OMC::parseAnnotationString(QString annotation)
     199void Component::parseAnnotationString(QString annotation)
    200200{
    201201  // parse the annotation string
     
    236236      shape = shape.mid(QString("Line").length());
    237237      shape = StringHandler::removeFirstLastBrackets(shape);
    238       LineAnnotation_OMC *pLineAnnotation = new LineAnnotation_OMC(shape, this);
     238      LineAnnotation *pLineAnnotation = new LineAnnotation(shape, this);
    239239      mpShapesList.append(pLineAnnotation);
    240240    }
     
    243243      shape = shape.mid(QString("Polygon").length());
    244244      shape = StringHandler::removeFirstLastBrackets(shape);
    245       PolygonAnnotation_OMC *pPolygonAnnotation = new PolygonAnnotation_OMC(shape, this);
     245      PolygonAnnotation *pPolygonAnnotation = new PolygonAnnotation(shape, this);
    246246      mpShapesList.append(pPolygonAnnotation);
    247247    }
     
    250250      shape = shape.mid(QString("Rectangle").length());
    251251      shape = StringHandler::removeFirstLastBrackets(shape);
    252       RectangleAnnotation_OMC *pRectangleAnnotation = new RectangleAnnotation_OMC(shape, this);
     252      RectangleAnnotation *pRectangleAnnotation = new RectangleAnnotation(shape, this);
    253253      mpShapesList.append(pRectangleAnnotation);
    254254    }
     
    257257      shape = shape.mid(QString("Ellipse").length());
    258258      shape = StringHandler::removeFirstLastBrackets(shape);
    259       EllipseAnnotation_OMC *pEllipseAnnotation = new EllipseAnnotation_OMC(shape, this);
     259      EllipseAnnotation *pEllipseAnnotation = new EllipseAnnotation(shape, this);
    260260      mpShapesList.append(pEllipseAnnotation);
    261261    }
     
    268268        shape = shape.mid(QString("Text").length());
    269269        shape = StringHandler::removeFirstLastBrackets(shape);
    270         TextAnnotation_OMC *pTextAnnotation = new TextAnnotation_OMC(shape, this);
     270        TextAnnotation *pTextAnnotation = new TextAnnotation(shape, this);
    271271        mpShapesList.append(pTextAnnotation);
    272272      }
     
    282282}
    283283
    284 void Component_OMC::getClassComponents()
    285 {
    286   foreach (Component_OMC *pInheritedComponent, mpInheritanceList)
     284void Component::getClassComponents()
     285{
     286  foreach (Component *pInheritedComponent, mpInheritanceList)
    287287  {
    288288    pInheritedComponent->getClassComponents();
     
    310310      {
    311311        QString result = mpOMCProxy->getIconAnnotation(pComponentInfo->getClassName());
    312         Component_OMC *pComponent = new Component_OMC(result, componentsAnnotations.at(i), pComponentInfo, StringHandler::CONNECTOR,
     312        Component *pComponent = new Component(result, componentsAnnotations.at(i), pComponentInfo, StringHandler::CONNECTOR,
    313313                                                      getRootParentComponent());
    314314        mpComponentsList.append(pComponent);
     
    319319}
    320320
    321 void Component_OMC::createActions()
     321void Component::createActions()
    322322{
    323323  // Properties Action
     
    331331}
    332332
    333 void Component_OMC::createResizerItems()
     333void Component::createResizerItems()
    334334{
    335335  qreal x1, y1, x2, y2;
     
    369369}
    370370
    371 void Component_OMC::getResizerItemsPositions(qreal *x1, qreal *y1, qreal *x2, qreal *y2)
     371void Component::getResizerItemsPositions(qreal *x1, qreal *y1, qreal *x2, qreal *y2)
    372372{
    373373  qreal x11, y11, x22, y22;
     
    395395}
    396396
    397 void Component_OMC::showResizerItems()
     397void Component::showResizerItems()
    398398{
    399399  qreal x1, y1, x2, y2;
     
    413413}
    414414
    415 void Component_OMC::hideResizerItems()
     415void Component::hideResizerItems()
    416416{
    417417  mpBottomLeftResizerItem->setPassive();
     
    421421}
    422422
    423 QRectF Component_OMC::boundingRect() const
     423QRectF Component::boundingRect() const
    424424{
    425425  qreal left = mpCoOrdinateSystem->getExtent().at(0).x();
     
    430430}
    431431
    432 void Component_OMC::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
     432void Component::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
    433433{
    434434  Q_UNUSED(painter);
     
    437437}
    438438
    439 QString Component_OMC::getName()
     439QString Component::getName()
    440440{
    441441  return mName;
    442442}
    443443
    444 QString Component_OMC::getClassName()
     444QString Component::getClassName()
    445445{
    446446  return mClassName;
    447447}
    448448
    449 StringHandler::ModelicaClasses Component_OMC::getType()
     449StringHandler::ModelicaClasses Component::getType()
    450450{
    451451  return mType;
    452452}
    453453
    454 OMCProxy* Component_OMC::getOMCProxy()
     454OMCProxy* Component::getOMCProxy()
    455455{
    456456  return mpOMCProxy;
    457457}
    458458
    459 GraphicsView* Component_OMC::getGraphicsView()
     459GraphicsView* Component::getGraphicsView()
    460460{
    461461  return mpGraphicsView;
    462462}
    463463
    464 Component_OMC* Component_OMC::getParentComponent()
     464Component* Component::getParentComponent()
    465465{
    466466  return mpParentComponent;
    467467}
    468468
    469 Component_OMC* Component_OMC::getRootParentComponent()
    470 {
    471   Component_OMC *pComponent;
     469Component* Component::getRootParentComponent()
     470{
     471  Component *pComponent;
    472472  pComponent = this;
    473473  while (pComponent->mpParentComponent)
     
    476476}
    477477
    478 Transformation* Component_OMC::getTransformation()
     478Transformation* Component::getTransformation()
    479479{
    480480  return mpTransformation;
    481481}
    482482
    483 QList<Component_OMC*> Component_OMC::getInheritanceList()
     483QList<Component*> Component::getInheritanceList()
    484484{
    485485  return mpInheritanceList;
    486486}
    487487
    488 ComponentInfo* Component_OMC::getComponentInfo()
     488ComponentInfo* Component::getComponentInfo()
    489489{
    490490  return mpComponentInfo;
    491491}
    492492
    493 QList<ShapeAnnotation_OMC*> Component_OMC::getShapesList()
     493QList<ShapeAnnotation*> Component::getShapesList()
    494494{
    495495  return mpShapesList;
    496496}
    497497
    498 QList<Component_OMC*> Component_OMC::getComponentsList()
     498QList<Component*> Component::getComponentsList()
    499499{
    500500  return mpComponentsList;
    501501}
    502502
    503 void Component_OMC::setOldPosition(QPointF oldPosition)
     503void Component::setOldPosition(QPointF oldPosition)
    504504{
    505505  mOldPosition = oldPosition;
    506506}
    507507
    508 QPointF Component_OMC::getOldPosition()
     508QPointF Component::getOldPosition()
    509509{
    510510  return mOldPosition;
    511511}
    512512
    513 void Component_OMC::setMousePressed(bool On)
     513void Component::setMousePressed(bool On)
    514514{
    515515  mIsMousePressed = On;
    516516}
    517517
    518 void Component_OMC::setComponentFlags()
     518void Component::setComponentFlags()
    519519{
    520520  // set the item flags
     
    527527}
    528528
    529 void Component_OMC::unsetComponentFlags()
     529void Component::unsetComponentFlags()
    530530{
    531531  // unset the item flags
     
    538538}
    539539
    540 void Component_OMC::getExtents(QPointF *pExtent1, QPointF *pExtent2)
     540void Component::getExtents(QPointF *pExtent1, QPointF *pExtent2)
    541541{
    542542  qreal x1, y1, x2, y2;
     
    568568}
    569569
    570 QString Component_OMC::getTransformationAnnotationString()
     570QString Component::getTransformationAnnotationString()
    571571{
    572572  QString annotationString;
     
    590590}
    591591
    592 QString Component_OMC::getPlacementAnnotation()
     592QString Component::getPlacementAnnotation()
    593593{
    594594  // create the placement annotation string
     
    600600    {
    601601      // first get the component from diagram view and get the transformations
    602       Component_OMC *pComponent;
    603       pComponent = mpGraphicsView->getModelWidget()->getDiagramGraphicsView()->getComponent_OMCObject(getName());
     602      Component *pComponent;
     603      pComponent = mpGraphicsView->getModelWidget()->getDiagramGraphicsView()->getComponentObject(getName());
    604604      if (pComponent)
    605605        placementAnnotationString.append(", ").append(pComponent->getTransformationAnnotationString());
     
    612612      placementAnnotationString.append(", ").append(getTransformationAnnotationString());
    613613      // then get the icon transformations
    614       Component_OMC *pComponent;
    615       pComponent = mpGraphicsView->getModelWidget()->getIconGraphicsView()->getComponent_OMCObject(getName());
     614      Component *pComponent;
     615      pComponent = mpGraphicsView->getModelWidget()->getIconGraphicsView()->getComponentObject(getName());
    616616      if (pComponent)
    617617        placementAnnotationString.append(", ").append(pComponent->getTransformationAnnotationString());
     
    626626}
    627627
    628 void Component_OMC::updatePlacementAnnotation()
     628void Component::updatePlacementAnnotation()
    629629{
    630630  // Add component annotation.
     
    636636}
    637637
    638 void Component_OMC::applyRotation(qreal angle)
     638void Component::applyRotation(qreal angle)
    639639{
    640640  mpTransformation->setRotateAngle(angle);
     
    646646}
    647647
    648 void Component_OMC::addConnectionDetails(LineAnnotation_OMC *pConnectorLineAnnotation)
     648void Component::addConnectionDetails(LineAnnotation *pConnectorLineAnnotation)
    649649{
    650650  // handle component position, rotation and scale changes
     
    659659}
    660660
    661 void Component_OMC::updateConnection()
     661void Component::updateConnection()
    662662{
    663663  emit componentTransformHasChanged();
    664664}
    665665
    666 void Component_OMC::prepareResizeShape(ResizerItem *pResizerItem)
     666void Component::prepareResizeShape(ResizerItem *pResizerItem)
    667667{
    668668  hideResizerItems();
     
    699699}
    700700
    701 void Component_OMC::resizeShape(int index, QPointF newPosition)
     701void Component::resizeShape(int index, QPointF newPosition)
    702702{
    703703  Q_UNUSED(index);
     
    741741}
    742742
    743 void Component_OMC::finishResizeShape()
     743void Component::finishResizeShape()
    744744{
    745745  qreal x1, y1, x2, y2;
     
    813813}
    814814
    815 void Component_OMC::updateShapePosition()
     815void Component::updateShapePosition()
    816816{
    817817  // update the placement annotation of the component
     
    820820}
    821821
    822 void Component_OMC::deleteMe()
     822void Component::deleteMe()
    823823{
    824824  // delete the component from model
    825   mpGraphicsView->deleteComponent_OMCObject(this);
     825  mpGraphicsView->deleteComponentObject(this);
    826826  // remove the component from the scene
    827827  mpGraphicsView->scene()->removeItem(this);
     
    831831}
    832832
    833 void Component_OMC::rotateClockwise()
     833void Component::rotateClockwise()
    834834{
    835835  qreal oldRotation = mpTransformation->getRotateAngle();
     
    845845}
    846846
    847 void Component_OMC::rotateAntiClockwise()
     847void Component::rotateAntiClockwise()
    848848{
    849849  qreal oldRotation = mpTransformation->getRotateAngle();
     
    863863//! @see moveLeft()
    864864//! @see moveRight()
    865 void Component_OMC::moveUp()
     865void Component::moveUp()
    866866{
    867867  mpTransformation->setOrigin(QPointF(mpTransformation->getOrigin().x(), mpTransformation->getOrigin().y() + 1));
     
    876876//! @see moveLeft()
    877877//! @see moveRight()
    878 void Component_OMC::moveDown()
     878void Component::moveDown()
    879879{
    880880  mpTransformation->setOrigin(QPointF(mpTransformation->getOrigin().x(), mpTransformation->getOrigin().y() - 1));
     
    889889//! @see moveDown()
    890890//! @see moveRight()
    891 void Component_OMC::moveLeft()
     891void Component::moveLeft()
    892892{
    893893  mpTransformation->setOrigin(QPointF(mpTransformation->getOrigin().x() - 1, mpTransformation->getOrigin().y()));
     
    902902//! @see moveDown()
    903903//! @see moveLeft()
    904 void Component_OMC::moveRight()
     904void Component::moveRight()
    905905{
    906906  mpTransformation->setOrigin(QPointF(mpTransformation->getOrigin().x() + 1, mpTransformation->getOrigin().y()));
     
    911911}
    912912
    913 void Component_OMC::mousePressEvent(QGraphicsSceneMouseEvent *event)
     913void Component::mousePressEvent(QGraphicsSceneMouseEvent *event)
    914914{
    915915  // if user is viewing the component in Icon View
     
    937937
    938938//! Event when mouse cursor enters component icon.
    939 void Component_OMC::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
     939void Component::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
    940940{
    941941  Q_UNUSED(event);
     
    946946
    947947//! Event when mouse cursor leaves component icon.
    948 void Component_OMC::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
     948void Component::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
    949949{
    950950  Q_UNUSED(event);
     
    954954}
    955955
    956 void Component_OMC::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
     956void Component::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
    957957{
    958958  // if we are viewing some readonly component then don't show the contextmenu
     
    960960    return;
    961961  setSelected(true);
    962   Component_OMC *pComponent = getRootParentComponent();
     962  Component *pComponent = getRootParentComponent();
    963963  QMenu menu(mpGraphicsView);
    964964  menu.icon();
     
    973973}
    974974
    975 QVariant Component_OMC::itemChange(GraphicsItemChange change, const QVariant &value)
     975QVariant Component::itemChange(GraphicsItemChange change, const QVariant &value)
    976976{
    977977  QGraphicsItem::itemChange(change, value);
     
    10571057}
    10581058
    1059 
    1060 
    1061 
    1062 
    1063 
    1064 
    1065 
    1066 
    1067 
    1068 Component::Component(QString value, QString name, QString className, QString transformationString, QPointF position, bool connector,
    1069                      OMCProxy *omc, GraphicsView *graphicsView, Component *pParent)
    1070   : ShapeAnnotation(graphicsView, pParent), mAnnotationString(value), mName(name), mClassName(className),
    1071     mTransformationString(transformationString), mIsConnector(connector), mpOMCProxy(omc), mpGraphicsView(graphicsView)
    1072 {
    1073   mIsLibraryComponent = false;
    1074   mpParentComponent = pParent;
    1075   initialize();
    1076   mpTransformation->parseTransformationString(transformationString, boundingRect().width(), boundingRect().height());
    1077   if (transformationString.isEmpty())
    1078   {
    1079     mpTransformation->setOrigin(position);
    1080     mpTransformation->setExtent1(QPointF(mInitialScale * mRectangle.left(), mInitialScale * mRectangle.top()));
    1081     mpTransformation->setExtent2(QPointF(mInitialScale * mRectangle.right(), mInitialScale * mRectangle.bottom()));
    1082     mpTransformation->setRotateAngle(0.0);
    1083   }
    1084   setTransform(mpTransformation->getTransformationMatrix());
    1085   if (mpGraphicsView->getModelWidget()->getLibraryTreeNode()->isReadOnly())
    1086   {
    1087     getClassInheritedComponents();
    1088     parseAnnotationString(value);
    1089     getClassComponents();
    1090   }
    1091   else
    1092   {
    1093     setComponentFlags();
    1094     setAcceptHoverEvents(true);
    1095     getClassInheritedComponents();
    1096     parseAnnotationString(value);
    1097     getClassComponents();
    1098     createResizerItems();
    1099     createActions();
    1100   }
    1101   // if everything is fine with icon then add it to scene
    1102   mpGraphicsView->scene()->addItem(this);
    1103   // if type is diagram then allow connections not for icon view
    1104   if (mIsConnector && !isLibraryComponent())
    1105     connect(this, SIGNAL(componentClicked(Component*)), mpGraphicsView, SLOT(addConnector(Component*)));
    1106 }
    1107 
    1108 /* Called for inheritance annotation instance */
    1109 Component::Component(QString value, QString className, bool connector, Component *pParent)
    1110   : ShapeAnnotation(pParent), mAnnotationString(value), mClassName(className), mIsConnector(connector)
    1111 {
    1112   mpParentComponent = pParent;
    1113   mIsLibraryComponent = mpParentComponent->isLibraryComponent() ? true : false;
    1114   mpOMCProxy = pParent->mpOMCProxy;
    1115   mpComponentProperties = 0;
    1116   mpTransformation = 0;
    1117   mpGraphicsView = isLibraryComponent() ? 0 : pParent->mpGraphicsView;
    1118   initialize();
    1119   getClassInheritedComponents();
    1120   parseAnnotationString(mAnnotationString);
    1121 }
    1122 
    1123 /* Called for component annotation instance */
    1124 Component::Component(QString value, QString transformationString, ComponentInfo *pComponentInfo, bool connector,
    1125                      Component *pParent)
    1126   : ShapeAnnotation(pParent), mAnnotationString(value), mTransformationString(transformationString),
    1127     mpComponentProperties(pComponentInfo), mIsConnector(connector)
    1128 {
    1129   mName = mpComponentProperties->getName();
    1130   mClassName = mpComponentProperties->getClassName();
    1131   mpParentComponent = pParent;
    1132   mIsLibraryComponent = mpParentComponent->isLibraryComponent() ? true : false;
    1133   mpOMCProxy = pParent->mpOMCProxy;
    1134   mpGraphicsView = isLibraryComponent() ? 0 : pParent->mpGraphicsView;
    1135   initialize();
    1136   parseAnnotationString(mAnnotationString);
    1137   mpTransformation->parseTransformationString(transformationString, boundingRect().width(), boundingRect().height());
    1138   setTransform(mpTransformation->getTransformationMatrix());
    1139   // if is connector then allow connections
    1140   if (mIsConnector && !isLibraryComponent())
    1141     connect(this, SIGNAL(componentClicked(Component*)), mpGraphicsView, SLOT(addConnector(Component*)));
    1142 }
    1143 
    1144 /* Used for Library Component */
    1145 Component::Component(QString value, QString className, bool connector, OMCProxy *omc, Component *pParent)
    1146   : ShapeAnnotation(pParent), mAnnotationString(value), mClassName(className), mIsConnector(connector), mpOMCProxy(omc)
    1147 {
    1148   mIsLibraryComponent = true;
    1149   mpParentComponent = pParent;
    1150   mpComponentProperties = 0;
    1151   // parse the annotation string
    1152   initialize();
    1153   getClassInheritedComponents();
    1154   parseAnnotationString(value);
    1155   getClassComponents();
    1156 }
    1157 
    1158 Component::Component(Component *pComponent, QString name, QString transformationString, QPointF position, bool connector,
    1159                      GraphicsView *graphicsView, Component *pParent)
    1160   : ShapeAnnotation(graphicsView, pParent), mName(name), mTransformationString(transformationString), mIsConnector(connector),
    1161     mpGraphicsView(graphicsView)
    1162 {
    1163   mIsLibraryComponent = false;
    1164   mpParentComponent = pParent;
    1165   mClassName = pComponent->mClassName;
    1166   mpOMCProxy = mpGraphicsView->getModelWidget()->getModelWidgetContainer()->getMainWindow()->getOMCProxy();
    1167   mAnnotationString = pComponent->mAnnotationString;
    1168   // Assing the Graphics View of this component to passed component. In order to avoid exceptions
    1169   pComponent->mpGraphicsView = mpGraphicsView;
    1170   initialize();
    1171   mpTransformation->parseTransformationString(transformationString, boundingRect().width(), boundingRect().height());
    1172   if (transformationString.isEmpty())
    1173   {
    1174     mpTransformation->setOrigin(position);
    1175     mpTransformation->setExtent1(QPointF(mInitialScale * mRectangle.left(), mInitialScale * mRectangle.top()));
    1176     mpTransformation->setExtent2(QPointF(mInitialScale * mRectangle.right(), mInitialScale * mRectangle.bottom()));
    1177     mpTransformation->setRotateAngle(0.0);
    1178   }
    1179   setTransform(mpTransformation->getTransformationMatrix());
    1180   mpChildComponentInfo = pComponent->mpChildComponentInfo;
    1181   if (mpGraphicsView->getModelWidget()->getLibraryTreeNode()->isReadOnly())
    1182   {
    1183     copyClassInheritedComponents(pComponent);
    1184     parseAnnotationString(mAnnotationString);
    1185     copyClassComponents(pComponent);
    1186   }
    1187   else
    1188   {
    1189     setComponentFlags();
    1190     setAcceptHoverEvents(true);
    1191     copyClassInheritedComponents(pComponent);
    1192     parseAnnotationString(mAnnotationString);
    1193     copyClassComponents(pComponent);
    1194     createResizerItems();
    1195     createActions();
    1196     mpGraphicsView->scene()->clearSelection();
    1197     setSelected(true);
    1198   }
    1199   // if everything is fine with icon then add it to scene
    1200   mpGraphicsView->scene()->addItem(this);
    1201   // if type is diagram then allow connections not for icon view
    1202   if (mIsConnector && !isLibraryComponent())
    1203     connect(this, SIGNAL(componentClicked(Component*)), mpGraphicsView, SLOT(addConnector(Component*)));
    1204 }
    1205 
    1206 Component::~Component()
    1207 {
    1208   // delete all the list of shapes
    1209   foreach(ShapeAnnotation *shape, mpShapesList)
    1210   {
    1211     delete shape;
    1212   }
    1213 
    1214   //    // delete the list of all components
    1215   //    foreach(Component *component, mpComponentsList)
    1216   //        delete component;
    1217 
    1218   //    // delete the list of all inherited components
    1219   //    foreach(Component *component, mpInheritanceList)
    1220   //        delete component;
    1221 }
    1222 
    1223 bool Component::getIsConnector()
    1224 {
    1225   return mIsConnector;
    1226 }
    1227 
    1228 void Component::initialize()
    1229 {
    1230   mRectangle = QRectF (-100, -100, 200, 200);
    1231   mPreserveAspectRatio = true;
    1232   mInitialScale = 0.1;
    1233   mGrid.append(2.0);
    1234   mGrid.append(2.0);
    1235 }
    1236 
    1237 //! Parses the result of getIconAnnotation command.
    1238 //! @param value is the result of getIconAnnotation command obtained from OMC.
    1239 bool Component::parseAnnotationString(QString value)
    1240 {
    1241   foreach(ShapeAnnotation *shape, mpShapesList)
    1242   {
    1243     mpShapesList.removeOne(shape);
    1244     delete shape;
    1245   }
    1246   // parse the annotation string
    1247   value = StringHandler::removeFirstLastCurlBrackets(value);
    1248   if (value.isEmpty())
    1249   {
    1250     return false;
    1251   }
    1252   QStringList list = StringHandler::getStrings(value);
    1253   if (list.size() < 9)
    1254     return false;
    1255   // read the coordinate system
    1256   qreal x1, x2, y1, y2, width, height;
    1257   x1 = static_cast<QString>(list.at(0)).toFloat();
    1258   y1 = static_cast<QString>(list.at(1)).toFloat();
    1259   x2 = static_cast<QString>(list.at(2)).toFloat();
    1260   y2 = static_cast<QString>(list.at(3)).toFloat();
    1261   width = fabs(x1 - x2);
    1262   height = fabs(y1 - y2);
    1263   mRectangle = QRectF (x1, y1, width, height);
    1264   // if the list is less that 5 then return
    1265   if (list.size() < 5)
    1266     return true;
    1267   // read aspectratio, scale, grid and shapes
    1268   QStringList shapesList;
    1269   mPreserveAspectRatio = static_cast<QString>(list.at(4)).contains("true");
    1270   mInitialScale = static_cast<QString>(list.at(5)).toFloat();
    1271   mGrid.append(static_cast<QString>(list.at(6)).toFloat());
    1272   mGrid.append(static_cast<QString>(list.at(7)).toFloat());
    1273   shapesList = StringHandler::getStrings(StringHandler::removeFirstLastCurlBrackets(list.at(8)), '(', ')');
    1274   // Now parse the shapes available in list
    1275   foreach (QString shape, shapesList)
    1276   {
    1277     shape = StringHandler::removeFirstLastCurlBrackets(shape);
    1278     if (shape.startsWith("Line"))
    1279     {
    1280       shape = shape.mid(QString("Line").length());
    1281       shape = StringHandler::removeFirstLastBrackets(shape);
    1282       LineAnnotation *lineAnnotation = new LineAnnotation(shape, this);
    1283       mpShapesList.append(lineAnnotation);
    1284     }
    1285     if (shape.startsWith("Polygon"))
    1286     {
    1287       shape = shape.mid(QString("Polygon").length());
    1288       shape = StringHandler::removeFirstLastBrackets(shape);
    1289       PolygonAnnotation *polygonAnnotation = new PolygonAnnotation(shape, this);
    1290       mpShapesList.append(polygonAnnotation);
    1291     }
    1292     if (shape.startsWith("Rectangle"))
    1293     {
    1294       shape = shape.mid(QString("Rectangle").length());
    1295       shape = StringHandler::removeFirstLastBrackets(shape);
    1296       RectangleAnnotation *rectangleAnnotation = new RectangleAnnotation(shape, this);
    1297       mpShapesList.append(rectangleAnnotation);
    1298     }
    1299     if (shape.startsWith("Ellipse"))
    1300     {
    1301       shape = shape.mid(QString("Ellipse").length());
    1302       shape = StringHandler::removeFirstLastBrackets(shape);
    1303       EllipseAnnotation *ellipseAnnotation = new EllipseAnnotation(shape, this);
    1304       mpShapesList.append(ellipseAnnotation);
    1305     }
    1306     // don't parse the text annotation for library icon
    1307     //! @todo We don't show text for Library Icons.
    1308     if (!isLibraryComponent())
    1309     {
    1310       if (shape.startsWith("Text"))
    1311       {
    1312         shape = shape.mid(QString("Text").length());
    1313         shape = StringHandler::removeFirstLastBrackets(shape);
    1314         TextAnnotation *textAnnotation = new TextAnnotation(shape, this);
    1315         mpShapesList.append(textAnnotation);
    1316       }
    1317     }
    1318     if (shape.startsWith("Bitmap"))
    1319     {
    1320       shape = shape.mid(QString("Bitmap").length());
    1321       shape = StringHandler::removeFirstLastBrackets(shape);
    1322       BitmapAnnotation *bitmapAnnotation = new BitmapAnnotation(shape, this);
    1323       mpShapesList.append(bitmapAnnotation);
    1324     }
    1325   }
    1326 }
    1327 
    1328 QRectF Component::boundingRect() const
    1329 {
    1330   return mRectangle;
    1331 }
    1332 
    1333 void Component::createActions()
    1334 {
    1335   // Icon Attributes Action
    1336   mpIconAttributesAction = new QAction(tr("Attributes"), mpGraphicsView);
    1337   mpIconAttributesAction->setStatusTip(tr("Shows the item attributes"));
    1338   connect(mpIconAttributesAction, SIGNAL(triggered()), SLOT(openIconAttributes()));
    1339   // Icon Properties Action
    1340   mpIconPropertiesAction = new QAction(QIcon(":/Resources/icons/tool.png"), tr("Properties"), mpGraphicsView);
    1341   mpIconPropertiesAction->setStatusTip(tr("Shows the item properties"));
    1342   connect(mpIconPropertiesAction, SIGNAL(triggered()), SLOT(openIconProperties()));
    1343 }
    1344 
    1345 void Component::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
    1346 {
    1347   //Q_UNUSED(painter);
    1348   Q_UNUSED(option);
    1349   Q_UNUSED(widget);
    1350   //painter->drawRect(boundingRect());
    1351 }
    1352 
    1353 void Component::mousePressEvent(QGraphicsSceneMouseEvent *event)
    1354 {
    1355   MainWindow *pMainWindow = mpGraphicsView->getModelWidget()->getModelWidgetContainer()->getMainWindow();
    1356   // if user is viewing the component in Icon View
    1357   if ((mpGraphicsView->getViewType() == StringHandler::ICON) or (mpGraphicsView->getModelWidget()->getLibraryTreeNode()->isReadOnly()))
    1358     return;
    1359 
    1360   // if component is a connector type then emit the componentClicked signal
    1361   if (event->button() == Qt::LeftButton  && pMainWindow->getConnectModeAction()->isChecked() && mIsConnector)
    1362   {
    1363     emit componentClicked(this);
    1364   }
    1365 
    1366   // if we are creating the connector then make sure user can not select and move components
    1367   if ((mpGraphicsView->isCreatingConnection()) and !mpParentComponent)
    1368   {
    1369     unsetComponentFlags();
    1370     return;
    1371   }
    1372   // if user not creating connector then check if the item flags are active or not
    1373   else if (!mpParentComponent)
    1374   {
    1375     setComponentFlags();
    1376   }
    1377 
    1378   // call the mouse press event only if component is the root component
    1379 //  if (!mpParentComponent)
    1380 //  {
    1381 //    QGraphicsItem::mousePressEvent(event);
    1382 //  }
    1383   QGraphicsItem::mousePressEvent(event);
    1384 }
    1385 
    1386 void Component::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
    1387 {
    1388   QGraphicsItem::mouseReleaseEvent(event);
    1389 }
    1390 
    1391 //! Event when mouse cursor enters component icon.
    1392 void Component::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
    1393 {
    1394   Q_UNUSED(event);
    1395   // if we are creating the connector then don't show selection box on hover events
    1396   if (mpGraphicsView->isCreatingConnection())
    1397     return;
    1398   if (!isSelected())
    1399     setResizerItemsHover();
    1400 }
    1401 
    1402 //! Event when mouse cursor leaves component icon.
    1403 void Component::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
    1404 {
    1405   Q_UNUSED(event);
    1406   if(!isSelected())
    1407     hideResizerItems();
    1408 }
    1409 
    1410 void Component::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
    1411 {
    1412   // if we are viewing some readonly component then don't show the contextmenu
    1413   if (mpGraphicsView->getModelWidget()->getLibraryTreeNode()->isReadOnly())
    1414     return;
    1415 
    1416   // get the root component, it could be either icon or diagram
    1417   setSelected(true);
    1418   Component *pComponent = getRootParentComponent();
    1419   QMenu menu(pComponent->mpGraphicsView->getModelWidget()->getModelWidgetContainer()->getMainWindow());
    1420   menu.addAction(pComponent->mpGraphicsView->mpRotateIconAction);
    1421   menu.addAction(pComponent->mpGraphicsView->mpRotateAntiIconAction);
    1422   menu.addAction(pComponent->mpGraphicsView->mpResetRotation);
    1423   //menu.addAction(pComponent->mpGraphicsView->mpHorizontalFlipAction);
    1424   //menu.addAction(pComponent->mpGraphicsView->mpVerticalFlipAction);
    1425   menu.addSeparator();
    1426   menu.addAction(pComponent->mpGraphicsView->mpDeleteIconAction);
    1427   //menu.addAction(pComponent->mpGraphicsView->mpCopyComponentAction);
    1428 //  if (pComponent->mType == StringHandler::ICON)
    1429 //  {
    1430 //    menu.addSeparator();
    1431 //    menu.addAction(pComponent->mpIconAttributesAction);
    1432 //    menu.addAction(pComponent->mpIconPropertiesAction);
    1433 //    menu.addSeparator();
    1434 //    //    if(mIsConnector==true)
    1435 //    //menu.addAction(pComponent->mpIsConnectModeAction);
    1436 //  }
    1437   menu.exec(event->screenPos());
    1438 }
    1439 
    1440 QVariant Component::itemChange(GraphicsItemChange change, const QVariant &value)
    1441 {
    1442   QGraphicsItem::itemChange(change, value);
    1443 
    1444   if (change == QGraphicsItem::ItemSelectedHasChanged)
    1445   {
    1446     if (isSelected())
    1447     {
    1448       showResizerItems();
    1449       setCursor(Qt::SizeAllCursor);
    1450       connect(mpGraphicsView->mpHorizontalFlipAction, SIGNAL(triggered()), SLOT(flipHorizontal()));
    1451       connect(mpGraphicsView->mpVerticalFlipAction, SIGNAL(triggered()), SLOT(flipVertical()));
    1452       connect(mpGraphicsView->mpRotateIconAction, SIGNAL(triggered()), SLOT(rotateClockwise()));
    1453       connect(mpGraphicsView->mpRotateAntiIconAction, SIGNAL(triggered()), SLOT(rotateAntiClockwise()));
    1454       connect(mpGraphicsView->mpResetRotation, SIGNAL(triggered()), SLOT(resetRotation()));
    1455       connect(mpGraphicsView->mpDeleteIconAction, SIGNAL(triggered()), SLOT(deleteMe()));
    1456       connect(mpGraphicsView->mpCopyComponentAction, SIGNAL(triggered()), SLOT(copyComponent()));
    1457       connect(mpGraphicsView, SIGNAL(keyPressDelete()), SLOT(deleteMe()));
    1458       connect(mpGraphicsView, SIGNAL(keyPressUp()), SLOT(moveUp()));
    1459       connect(mpGraphicsView, SIGNAL(keyPressDown()), SLOT(moveDown()));
    1460       connect(mpGraphicsView, SIGNAL(keyPressLeft()), SLOT(moveLeft()));
    1461       connect(mpGraphicsView, SIGNAL(keyPressRight()), SLOT(moveRight()));
    1462       connect(mpGraphicsView, SIGNAL(keyPressRotateClockwise()), SLOT(rotateClockwise()));
    1463       connect(mpGraphicsView, SIGNAL(keyPressRotateAntiClockwise()), SLOT(rotateAntiClockwise()));
    1464     }
    1465     else
    1466     {
    1467       if (!mpBottomLeftResizerItem->isPressed())
    1468         if (!mpTopLeftResizerItem->isPressed())
    1469           if (!mpTopRightResizerItem->isPressed())
    1470             if (!mpBottomRightResizerItem->isPressed())
    1471               hideResizerItems();
    1472       unsetCursor();
    1473       disconnect(mpGraphicsView->mpHorizontalFlipAction, SIGNAL(triggered()), this, SLOT(flipHorizontal()));
    1474       disconnect(mpGraphicsView->mpVerticalFlipAction, SIGNAL(triggered()), this, SLOT(flipVertical()));
    1475       disconnect(mpGraphicsView->mpRotateIconAction, SIGNAL(triggered()), this, SLOT(rotateClockwise()));
    1476       disconnect(mpGraphicsView->mpRotateAntiIconAction, SIGNAL(triggered()), this, SLOT(rotateAntiClockwise()));
    1477       disconnect(mpGraphicsView->mpResetRotation, SIGNAL(triggered()), this, SLOT(resetRotation()));
    1478       disconnect(mpGraphicsView->mpDeleteIconAction, SIGNAL(triggered()), this, SLOT(deleteMe()));
    1479       disconnect(mpGraphicsView->mpCopyComponentAction, SIGNAL(triggered()), this, SLOT(copyComponent()));
    1480       disconnect(mpGraphicsView, SIGNAL(keyPressDelete()), this, SLOT(deleteMe()));
    1481       disconnect(mpGraphicsView, SIGNAL(keyPressUp()), this, SLOT(moveUp()));
    1482       disconnect(mpGraphicsView, SIGNAL(keyPressDown()), this, SLOT(moveDown()));
    1483       disconnect(mpGraphicsView, SIGNAL(keyPressLeft()), this, SLOT(moveLeft()));
    1484       disconnect(mpGraphicsView, SIGNAL(keyPressRight()), this, SLOT(moveRight()));
    1485       disconnect(mpGraphicsView, SIGNAL(keyPressRotateClockwise()), this, SLOT(rotateClockwise()));
    1486       disconnect(mpGraphicsView, SIGNAL(keyPressRotateAntiClockwise()), this, SLOT(rotateAntiClockwise()));
    1487     }
    1488   }
    1489   else if (change == QGraphicsItem::ItemPositionHasChanged)
    1490   {
    1491     emit componentMoved();
    1492     // if user has changed the postion using the keyboard then update annotations
    1493     // if user changes the position with mouse we handle it in mouse events of graphicsview
    1494     if (!mIsMousePressed)
    1495     {
    1496       if (mIsConnector)
    1497       {
    1498         Component *pComponent;
    1499         if (mpGraphicsView->getViewType() == StringHandler::ICON)
    1500         {
    1501           pComponent = mpGraphicsView->getModelWidget()->getDiagramGraphicsView()->getComponentObject(getName());
    1502           pComponent->setPos(pos());
    1503         }
    1504         else if(mpGraphicsView->getViewType() == StringHandler::DIAGRAM)
    1505         {
    1506           //Component *pComponent;
    1507           pComponent = mpGraphicsView->getModelWidget()->getIconGraphicsView()->getComponentObject(getName());
    1508           pComponent->setPos(pos());
    1509         }
    1510         //if component is a connector, synchronize the position in its diagram view with the icon view
    1511         pComponent->updateAnnotationString();
    1512       }
    1513       updateAnnotationString();
    1514       // update connectors annotations that are associated to this component
    1515       emit componentPositionChanged();
    1516       ModelWidget *pModelWidget = mpGraphicsView->getModelWidget();
    1517       pModelWidget->getModelicaTextWidget()->getModelicaTextEdit()->setPlainText(mpOMCProxy->list(pModelWidget->getLibraryTreeNode()->getNameStructure()));
    1518     }
    1519   }
    1520 #if (QT_VERSION >= QT_VERSION_CHECK(4, 7, 0))
    1521   else if (change == QGraphicsItem::ItemRotationHasChanged)
    1522   {
    1523     emit componentRotated(true);
    1524     updateAnnotationString();
    1525     ModelWidget *pModelWidget = mpGraphicsView->getModelWidget();
    1526     pModelWidget->getModelicaTextWidget()->getModelicaTextEdit()->setPlainText(mpOMCProxy->list(pModelWidget->getLibraryTreeNode()->getNameStructure()));
    1527   }
    1528 #endif
    1529   return value;
    1530 }
    1531 
    1532 void Component::addConnector(Connector *item)
    1533 {
    1534   connect(this, SIGNAL(componentMoved()), item, SLOT(drawConnector()));
    1535   connect(this, SIGNAL(componentPositionChanged()), item, SLOT(updateConnectionAnnotationString()));
    1536 
    1537   connect(this, SIGNAL(componentRotated(bool)), item, SLOT(drawConnector(bool)));
    1538   connect(this, SIGNAL(componentRotated(bool)), item, SLOT(updateConnectionAnnotationString()));
    1539 
    1540   connect(this, SIGNAL(componentScaled()), item, SLOT(drawConnector()));
    1541   connect(this, SIGNAL(componentScaled()), item, SLOT(updateConnectionAnnotationString()));
    1542 }
    1543 
    1544 void Component::setComponentFlags()
    1545 {
    1546   // set the item flags
    1547   if(!flags().testFlag((QGraphicsItem::ItemIsMovable)))
    1548     setFlag(QGraphicsItem::ItemIsMovable);
    1549   if(!flags().testFlag((QGraphicsItem::ItemIsSelectable)))
    1550     setFlag(QGraphicsItem::ItemIsSelectable);
    1551   if(!flags().testFlag((QGraphicsItem::ItemSendsGeometryChanges)))
    1552     setFlag(QGraphicsItem::ItemSendsGeometryChanges);
    1553 }
    1554 
    1555 void Component::unsetComponentFlags()
    1556 {
    1557   // unset the item flags
    1558   if(flags().testFlag((QGraphicsItem::ItemIsMovable)))
    1559     setFlag(QGraphicsItem::ItemIsMovable, false);
    1560   if(flags().testFlag((QGraphicsItem::ItemIsSelectable)))
    1561     setFlag(QGraphicsItem::ItemIsSelectable, false);
    1562   if(flags().testFlag((QGraphicsItem::ItemSendsGeometryChanges)))
    1563     setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
    1564 }
    1565 
    1566 QString Component::getTransformationAnnotationString()
    1567 {
    1568   QString annotationString;
    1569   if (mpGraphicsView->getViewType() == StringHandler::ICON)
    1570     annotationString.append("iconTransformation=transformation(origin=");
    1571   else if (mpGraphicsView->getViewType() == StringHandler::DIAGRAM)
    1572     annotationString.append("transformation=transformation(origin=");
    1573   // add the icon origin
    1574   annotationString.append("{").append(QString::number(scenePos().x())).append(",");
    1575   annotationString.append(QString::number(scenePos().y())).append("}, ");
    1576   // add extent points
    1577   qreal x1, y1, x2, y2;
    1578   boundingRect().getCoords(&x1, &y1, &x2, &y2);
    1579   QPointF extent1, extent2;
    1580   extent1.setX(mapToScene(x1, y1).x() - scenePos().x());
    1581   extent1.setY(mapToScene(x1, y1).y() - scenePos().y());
    1582   extent2.setX(mapToScene(x2, y2).x() - scenePos().x());
    1583   extent2.setY(mapToScene(x2, y2).y() - scenePos().y());
    1584   if (mpTransformation->getFlipHorizontal())
    1585   {
    1586     extent1.setX(fabs(extent1.x()));
    1587     extent2.setX(-(fabs(extent2.x())));
    1588   }
    1589   else
    1590   {
    1591     extent1.setX(-(fabs(extent1.x())));
    1592     extent2.setX(fabs(extent2.x()));
    1593   }
    1594   if (mpTransformation->getFlipVertical())
    1595   {
    1596     extent1.setY(fabs(extent1.y()));
    1597     extent2.setY(-(fabs(extent2.y())));
    1598   }
    1599   else
    1600   {
    1601     extent1.setY(-(fabs(extent1.y())));
    1602     extent2.setY(fabs(extent2.y()));
    1603   }
    1604   annotationString.append("extent={").append("{").append(QString::number(extent1.x()));
    1605   annotationString.append(",").append(QString::number(extent1.y())).append("},");
    1606   annotationString.append("{").append(QString::number(extent2.x())).append(",");
    1607   annotationString.append(QString::number(extent2.y())).append("}}, ");
    1608   // add icon rotation
    1609   annotationString.append("rotation=").append(QString::number(mpTransformation->getRotateAngle())).append(")");
    1610   return annotationString;
    1611 }
    1612 
    1613 void Component::updateAnnotationString(bool updateBothViews)
    1614 {
    1615   // create the annotation string
    1616   QString annotationString = "annotate=Placement(";
    1617   annotationString.append("visible=true, ");
    1618   if (mIsConnector and updateBothViews)
    1619   {
    1620     if (mpGraphicsView->getViewType() == StringHandler::ICON)
    1621     {
    1622       // first get the component from diagram view and get the transformations
    1623       Component *pComponent;
    1624       pComponent = mpGraphicsView->getModelWidget()->getDiagramGraphicsView()->getComponentObject(getName());
    1625       if (pComponent)
    1626         annotationString.append(pComponent->getTransformationAnnotationString());
    1627       // then get the icon transformations
    1628       annotationString.append(QString(", ").append(getTransformationAnnotationString()));
    1629     }
    1630     else if (mpGraphicsView->getViewType() == StringHandler::DIAGRAM)
    1631     {
    1632       // first get the component from diagram view and get the transformations
    1633       annotationString.append(getTransformationAnnotationString());
    1634       // then get the icon transformations
    1635       Component *pComponent;
    1636       pComponent = mpGraphicsView->getModelWidget()->getIconGraphicsView()->getComponentObject(getName());
    1637       if (pComponent)
    1638         annotationString.append(QString(", ").append(pComponent->getTransformationAnnotationString()));
    1639     }
    1640   }
    1641   else
    1642   {
    1643     annotationString.append(getTransformationAnnotationString());
    1644   }
    1645   annotationString.append(")");
    1646   // Add component annotation.
    1647   mpOMCProxy->updateComponent(mName, mClassName, mpGraphicsView->getModelWidget()->getLibraryTreeNode()->getNameStructure(), annotationString);
    1648   // call the addclassannotation if the graphicsview is icon, so the icon in the tree is also updated
    1649   if (mpGraphicsView->getViewType() == StringHandler::ICON || mIsConnector)
    1650     mpGraphicsView->addClassAnnotation();
    1651 }
    1652 
    1653 //! Tells the component to ask its parent to delete it.
    1654 void Component::deleteMe(bool update)
    1655 {
    1656   // make sure you disconnect all signals before deleting the object
    1657   disconnect(mpGraphicsView->mpHorizontalFlipAction, SIGNAL(triggered()), this, SLOT(flipHorizontal()));
    1658   disconnect(mpGraphicsView->mpVerticalFlipAction, SIGNAL(triggered()), this, SLOT(flipVertical()));
    1659   disconnect(mpGraphicsView->mpRotateIconAction, SIGNAL(triggered()), this, SLOT(rotateClockwise()));
    1660   disconnect(mpGraphicsView->mpRotateAntiIconAction, SIGNAL(triggered()), this, SLOT(rotateAntiClockwise()));
    1661   disconnect(mpGraphicsView->mpResetRotation, SIGNAL(triggered()), this, SLOT(resetRotation()));
    1662   disconnect(mpGraphicsView->mpDeleteIconAction, SIGNAL(triggered()), this, SLOT(deleteMe()));
    1663   disconnect(mpGraphicsView->mpCopyComponentAction, SIGNAL(triggered()), this, SLOT(copyComponent()));
    1664   disconnect(mpGraphicsView, SIGNAL(keyPressDelete()), this, SLOT(deleteMe()));
    1665   disconnect(mpGraphicsView, SIGNAL(keyPressUp()), this, SLOT(moveUp()));
    1666   disconnect(mpGraphicsView, SIGNAL(keyPressDown()), this, SLOT(moveDown()));
    1667   disconnect(mpGraphicsView, SIGNAL(keyPressLeft()), this, SLOT(moveLeft()));
    1668   disconnect(mpGraphicsView, SIGNAL(keyPressRight()), this, SLOT(moveRight()));
    1669   disconnect(mpGraphicsView, SIGNAL(keyPressRotateClockwise()), this, SLOT(rotateClockwise()));
    1670   disconnect(mpGraphicsView, SIGNAL(keyPressRotateAntiClockwise()), this, SLOT(rotateAntiClockwise()));
    1671   // delete the object
    1672   GraphicsView *pGraphicsView = qobject_cast<GraphicsView*>(const_cast<QObject*>(sender()));
    1673   // delete the component from model
    1674   mpGraphicsView->deleteComponentObject(this, update);
    1675   // remove the component from the scene
    1676   mpGraphicsView->scene()->removeItem(this);
    1677   // if the signal is not send by graphicsview then call addclassannotation
    1678   if (!pGraphicsView)
    1679   {
    1680     if (mpGraphicsView->getViewType() == StringHandler::ICON)
    1681       mpGraphicsView->addClassAnnotation(update);
    1682   }
    1683   deleteLater();
    1684 }
    1685 
    1686 
    1687 //copying a component or a selected scene, currently non functional,just works for a single
    1688 //component, to do
    1689 void Component::copyComponent()
    1690 {
    1691   GraphicsView *pGraphicsView = qobject_cast<GraphicsView*>(const_cast<QObject*>(sender()));
    1692 
    1693   Component *newComponent;
    1694   QString name = mpGraphicsView->getUniqueComponentName(getName().toLower());
    1695   QPointF point;
    1696   point= QPointF((pos().x()) +1.0 ,(pos().y()) +1.0);
    1697   //newComponent = new Component(this,name,point,getIsConnector(),mpGraphicsView);
    1698   //remove the component from the scene
    1699   //mpGraphicsView->scene()->removeItem(this);
    1700   //if the signal is not send by graphicsview then call addclassannotation
    1701   //    if (!pGraphicsView)
    1702   //    {
    1703   //        if (mpGraphicsView->mIconType == StringHandler::ICON)
    1704   //            mpGraphicsView->addClassAnnotation();
    1705   //    }
    1706   //    delete(this);
    1707   //mpGraphicsView->addComponentObject(newComponent);
    1708 
    1709   QClipboard *clipboard = QApplication::clipboard();
    1710 
    1711 
    1712   clipboard->setText(getName());
    1713 
    1714   //if(!clipboard->text().isEmpty())
    1715   //mpGraphicsView->mpPasteComponentAction->setDisabled(false);
    1716 }
    1717 
    1718 void Component::openIconProperties()
    1719 {
    1720   IconProperties *iconProperties = new IconProperties(this, mpGraphicsView->getModelWidget()->getModelWidgetContainer()->getMainWindow());
    1721   iconProperties->show();
    1722 }
    1723 
    1724 void Component::openIconAttributes()
    1725 {
    1726   IconAttributes *iconAttributes = new IconAttributes(this, mpGraphicsView->getModelWidget()->getModelWidgetContainer()->getMainWindow());
    1727   iconAttributes->show();
    1728 }
    1729 
    1730 QString Component::getName()
    1731 {
    1732   return mName;
    1733 }
    1734 
    1735 void Component::updateName(QString newName)
    1736 {
    1737   // check in icon text annotation
    1738   foreach (ShapeAnnotation *shapeAnnotation, mpShapesList)
    1739   {
    1740     if (dynamic_cast<TextAnnotation*>(shapeAnnotation))
    1741     {
    1742       TextAnnotation *textAnnotation = dynamic_cast<TextAnnotation*>(shapeAnnotation);
    1743       if (textAnnotation->getTextString() == mName)
    1744       {
    1745         textAnnotation->setTextString(newName);
    1746         mName = newName;
    1747         return;
    1748       }
    1749     }
    1750   }
    1751 
    1752   // check in icon's inheritance text annotation
    1753   foreach (Component *inheritance, mpInheritanceList)
    1754     foreach (ShapeAnnotation *shapeAnnotation, inheritance->mpShapesList)
    1755     {
    1756       if (dynamic_cast<TextAnnotation*>(shapeAnnotation))
    1757       {
    1758         TextAnnotation *textAnnotation = dynamic_cast<TextAnnotation*>(shapeAnnotation);
    1759         if (textAnnotation->getTextString() == mName)
    1760         {
    1761           textAnnotation->setTextString(newName);
    1762           mName = newName;
    1763           return;
    1764         }
    1765       }
    1766     }
    1767 
    1768   // check in icon's components text annotation
    1769   foreach (Component *component, mpComponentsList)
    1770     foreach (ShapeAnnotation *shapeAnnotation, component->mpShapesList)
    1771     {
    1772       if (dynamic_cast<TextAnnotation*>(shapeAnnotation))
    1773       {
    1774         TextAnnotation *textAnnotation = dynamic_cast<TextAnnotation*>(shapeAnnotation);
    1775         if (textAnnotation->getTextString() == mName)
    1776         {
    1777           textAnnotation->setTextString(newName);
    1778           mName = newName;
    1779           return;
    1780         }
    1781       }
    1782     }
    1783 }
    1784 
    1785 void Component::updateParameterValue(QString oldValue, QString newValue)
    1786 {
    1787   // check in icon text annotation
    1788   foreach (ShapeAnnotation *shapeAnnotation, mpShapesList)
    1789   {
    1790     if (dynamic_cast<TextAnnotation*>(shapeAnnotation))
    1791     {
    1792       TextAnnotation *textAnnotation = dynamic_cast<TextAnnotation*>(shapeAnnotation);
    1793       if (textAnnotation->getTextString() == oldValue)
    1794       {
    1795         textAnnotation->setTextString(newValue);
    1796         return;
    1797       }
    1798     }
    1799   }
    1800 }
    1801 
    1802 QString Component::getClassName()
    1803 {
    1804   return mClassName;
    1805 }
    1806 
    1807 OMCProxy* Component::getOMCProxy()
    1808 {
    1809   return mpOMCProxy;
    1810 }
    1811 
    1812 GraphicsView* Component::getGraphicsView()
    1813 {
    1814   return mpGraphicsView;
    1815 }
    1816 
    1817 Component* Component::getParentComponent()
    1818 {
    1819   if (!mpParentComponent)
    1820     return this;
    1821   else
    1822     return mpParentComponent;
    1823 }
    1824 
    1825 Component* Component::getRootParentComponent(bool secondLast)
    1826 {
    1827   Component *pComponent, *pPreviousComponent;
    1828   pComponent = this;
    1829   pPreviousComponent = this;
    1830   while (pComponent->mpParentComponent)
    1831   {
    1832     pPreviousComponent = pComponent;
    1833     pComponent = pComponent->mpParentComponent;
    1834   }
    1835 
    1836   if (secondLast)
    1837     return pPreviousComponent;
    1838   else
    1839     return pComponent;
    1840 }
    1841 
    1842 QList<Component*> Component::getInheritanceList()
    1843 {
    1844   return mpInheritanceList;
    1845 }
    1846 
    1847 QList<ShapeAnnotation*> Component::getShapesList()
    1848 {
    1849   return mpShapesList;
    1850 }
    1851 
    1852 QList<Component*> Component::getComponentsList()
    1853 {
    1854   return mpComponentsList;
    1855 }
    1856 
    1857 ComponentInfo* Component::getComponentInfo()
    1858 {
    1859   return mpComponentProperties;
    1860 }
    1861 
    1862 QList<ComponentInfo*> Component::getChildComponentInfo()
    1863 {
    1864   return mpChildComponentInfo;
    1865 }
    1866 
    1867 QRectF Component::getRectangle()
    1868 {
    1869   return mRectangle;
    1870 }
    1871 
    1872 QString Component::getTransformationString()
    1873 {
    1874   return mTransformationString;
    1875 }
    1876 
    1877 bool Component::isLibraryComponent()
    1878 {
    1879   return mIsLibraryComponent;
    1880 }
    1881 
    1882 void Component::setOldPosition(QPointF oldPosition)
    1883 {
    1884   mOldPosition = oldPosition;
    1885 }
    1886 
    1887 QPointF Component::getOldPosition()
    1888 {
    1889   return mOldPosition;
    1890 }
    1891 
    1892 void Component::setMousePressed(bool On)
    1893 {
    1894   mIsMousePressed = On;
    1895 }
    1896 
    1897 void Component::getClassInheritedComponents()
    1898 {
    1899   // read the component inheritance
    1900   int inheritanceCount = mpOMCProxy->getInheritanceCount(mClassName);
    1901   for(int i = 1 ; i <= inheritanceCount ; i++)
    1902   {
    1903     QString inheritedClass = mpOMCProxy->getNthInheritedClass(mClassName, i);
    1904     // avoid cycles
    1905     if (inheritedClass.compare(mClassName) == 0)
    1906       return;
    1907     // If the inherited class is one of the builtin type such as Real we can
    1908     // stop here, because the class can not contain any components, etc.
    1909     if (mpOMCProxy->isBuiltinType(inheritedClass))
    1910     {
    1911       //mpInheritanceList.append(new Component("", inheritedClass, mpOMCProxy->isWhat(StringHandler::CONNECTOR, inheritedClass), this));
    1912       return;
    1913     }
    1914     // get the inherited class annotation
    1915     QString annotationString = mpOMCProxy->getIconAnnotation(inheritedClass);
    1916     Component *inheritance;
    1917     inheritance  = new Component(annotationString, inheritedClass, mpOMCProxy->isWhat(StringHandler::CONNECTOR, inheritedClass), this);
    1918     mpInheritanceList.append(inheritance);
    1919   }
    1920 }
    1921 
    1922 //! this function is called for icon view
    1923 void Component::getClassComponents()
    1924 {
    1925   foreach (Component *pInheritedComponent, mpInheritanceList)
    1926   {
    1927     pInheritedComponent->getClassComponents();
    1928   }
    1929   // get components
    1930   QList<ComponentInfo*> componentInfoList = mpOMCProxy->getComponents(mClassName);
    1931   mpChildComponentInfo = componentInfoList;
    1932   QStringList componentsAnnotationsList = mpOMCProxy->getComponentAnnotations(mClassName);
    1933   int i = 0;
    1934   foreach (ComponentInfo *pComponentInfo, componentInfoList)
    1935   {
    1936     // just to be on safe-side.
    1937     if (componentsAnnotationsList.size() <= i)
    1938       continue;
    1939     if (static_cast<QString>(componentsAnnotationsList.at(i)).toLower().contains("error"))
    1940     {
    1941       i++;
    1942       continue;
    1943     }
    1944     // if component is protected we don't show it in the diagram layer.
    1945     if (pComponentInfo->getProtected())
    1946     {
    1947       i++;
    1948       continue;
    1949     }
    1950     if (StringHandler::removeFirstLastCurlBrackets(componentsAnnotationsList.at(i)).length() > 0)
    1951     {
    1952       if (mpOMCProxy->isWhat(StringHandler::CONNECTOR, pComponentInfo->getClassName()))
    1953       {
    1954         QString result = mpOMCProxy->getIconAnnotation(pComponentInfo->getClassName());
    1955         Component *component;
    1956         if (mIsLibraryComponent)
    1957         {
    1958           component = new Component(result, componentsAnnotationsList.at(i), pComponentInfo, true, getRootParentComponent());
    1959         }
    1960         else
    1961         {
    1962           component = new Component(result, componentsAnnotationsList.at(i), pComponentInfo, true, getRootParentComponent());
    1963         }
    1964         mpComponentsList.append(component);
    1965       }
    1966     }
    1967     i++;
    1968   }
    1969 }
    1970 
    1971 //! this function is called for diagram view
    1972 //void Component::getClassComponents(QString className, int type, Component *pParent)
    1973 //{
    1974 //  // if component type is diagram then
    1975 //  if (type == StringHandler::DIAGRAM)
    1976 //  {
    1977 //    // get the diagram connections
    1978 //    int connections = mpOMCProxy->getConnectionCount(className);
    1979 
    1980 //    for (int i = 1 ; i <= connections ; i++)
    1981 //    {
    1982 //      QString result = mpOMCProxy->getNthConnectionAnnotation(className, i);
    1983 //      QStringList shapesList;
    1984 //      shapesList = StringHandler::getStrings(StringHandler::removeFirstLastCurlBrackets(result), '(', ')');
    1985 //      // Now parse the shapes available in list
    1986 //      foreach (QString shape, shapesList)
    1987 //      {
    1988 //        shape = StringHandler::removeFirstLastCurlBrackets(shape);
    1989 //        if (shape.startsWith("Line"))
    1990 //        {
    1991 //          shape = shape.mid(QString("Line").length());
    1992 //          result = StringHandler::removeFirstLastBrackets(shape);
    1993 //          LineAnnotation *lineAnnotation = new LineAnnotation(result, pParent);
    1994 //          Q_UNUSED(lineAnnotation);
    1995 //        }
    1996 //      }
    1997 //    }
    1998 //  }
    1999 
    2000 //  int inheritanceCount = mpOMCProxy->getInheritanceCount(className);
    2001 
    2002 //  for(int i = 1 ; i <= inheritanceCount ; i++)
    2003 //  {
    2004 //    QString inheritedClass = mpOMCProxy->getNthInheritedClass(className, i);
    2005 //    QString annotationString;
    2006 
    2007 //    // If the inherited class is one of the builtin type such as Real we can
    2008 //    // stop here, because the class can not contain any components, etc.
    2009 //    if (mpOMCProxy->isBuiltinType(inheritedClass))
    2010 //    {
    2011 //      mpInheritanceList.append(new Component("", inheritedClass, mpOMCProxy->isWhat(StringHandler::CONNECTOR, inheritedClass), this));
    2012 //      return;
    2013 //    }
    2014 //    if (type == StringHandler::ICON)
    2015 //      annotationString = mpOMCProxy->getIconAnnotation(inheritedClass);
    2016 //    else if (type == StringHandler::DIAGRAM)
    2017 //      annotationString = mpOMCProxy->getDiagramAnnotation(inheritedClass);
    2018 //    Component *inheritance;
    2019 //    inheritance = new Component(annotationString, inheritedClass, mpOMCProxy->isWhat(StringHandler::CONNECTOR, inheritedClass), pParent);
    2020 //    mpInheritanceList.append(inheritance);
    2021 //    // avoid cycles
    2022 //    if (inheritedClass.compare(className) == 0)
    2023 //    {
    2024 //      return;
    2025 //    }
    2026 //    getClassComponents(inheritedClass, type, inheritance);
    2027 //  }
    2028 
    2029 //  QList<ComponentsProperties*> components = mpOMCProxy->getComponents(className);
    2030 //  mpChildComponentProperties=components;
    2031 
    2032 //  QStringList componentsAnnotationsList = mpOMCProxy->getComponentAnnotations(className);
    2033 //  int i = 0;
    2034 //  foreach (ComponentsProperties *componentProperties, components)
    2035 //  {
    2036 //    if (static_cast<QString>(componentsAnnotationsList.at(i)).toLower().contains("error"))
    2037 //      continue;
    2038 
    2039 //    if (type == StringHandler::ICON)
    2040 //    {
    2041 //      if (StringHandler::removeFirstLastCurlBrackets(componentsAnnotationsList.at(i)).length() > 0)
    2042 //      {
    2043 //        if (mpOMCProxy->isWhat(StringHandler::CONNECTOR, componentProperties->getClassName()))
    2044 //        {
    2045 //          QString result = mpOMCProxy->getIconAnnotation(componentProperties->getClassName());
    2046 //          Component *component;
    2047 //          component = new Component(result, componentsAnnotationsList.at(i), componentProperties, true, pParent);
    2048 //          mpComponentsList.append(component);
    2049 //          getClassComponents(componentProperties->getClassName(), StringHandler::ICON, component);
    2050 //        }
    2051 //      }
    2052 //      else
    2053 //      {
    2054 //        //! @todo Change it to add all components.............
    2055 //        mpComponentProperties = components.at(0);
    2056 //      }
    2057 //    }
    2058 //    else if (type == StringHandler::DIAGRAM)
    2059 //    {
    2060 //      if (StringHandler::removeFirstLastCurlBrackets(componentsAnnotationsList.at(i)).length() > 0)
    2061 //      {
    2062 //        if (mpOMCProxy->isWhat(StringHandler::CONNECTOR, componentProperties->getClassName()))
    2063 //        {
    2064 //          QString result = mpOMCProxy->getDiagramAnnotation(componentProperties->getClassName());
    2065 //          Component *component;
    2066 //          component = new Component(result, componentsAnnotationsList.at(i), componentProperties, true, pParent);
    2067 //          mpComponentsList.append(component);
    2068 //          getClassComponents(componentProperties->getClassName(), StringHandler::DIAGRAM, component);
    2069 //        }
    2070 //        else
    2071 //        {
    2072 //          QString result = mpOMCProxy->getIconAnnotation(componentProperties->getClassName());
    2073 //          Component *component;
    2074 //          component = new Component(result, componentsAnnotationsList.at(i), componentProperties, true, pParent);
    2075 //          mpComponentsList.append(component);
    2076 //          getClassComponents(componentProperties->getClassName(), StringHandler::ICON, component);
    2077 //        }
    2078 //      }
    2079 //    }
    2080 //    i++;
    2081 //  }
    2082 //}
    2083 
    2084 void Component::copyClassInheritedComponents(Component *pComponent)
    2085 {
    2086   foreach(Component *inheritance, pComponent->mpInheritanceList)
    2087   {
    2088     Component *inheritanceComponent = new Component(inheritance->mAnnotationString, inheritance->mClassName, inheritance->mIsConnector, this);
    2089     inheritanceComponent->mpComponentsList = inheritance->mpComponentsList;
    2090     mpInheritanceList.append(inheritanceComponent);
    2091   }
    2092 }
    2093 
    2094 //! this function is called when we need to create a copy of one component
    2095 void Component::copyClassComponents(Component *pComponent)
    2096 {
    2097   foreach(Component *inheritance, mpInheritanceList)
    2098   {
    2099     inheritance->copyClassComponents(inheritance);
    2100   }
    2101   foreach(Component *component, pComponent->mpComponentsList)
    2102   {
    2103     Component *portComponent = new Component(component->mAnnotationString, component->mTransformationString, component->mpComponentProperties,
    2104                                              component->mIsConnector, getRootParentComponent());
    2105     mpComponentsList.append(portComponent);
    2106   }
    2107 }
    2108 
    2109 
    2110 
    2111 
    2112 
    21131059ComponentInfo::ComponentInfo(QString value)
    21141060{
     
    21331079  mCasuality = "";
    21341080  mArrayIndex = "";
     1081  mIsArray = false;
    21351082  parseString(value);
    21361083}
     
    22171164  // read the array index value
    22181165  mArrayIndex = StringHandler::removeFirstLastCurlBrackets(list.at(11));
     1166  if ((mArrayIndex.compare("n") == 0) || (mArrayIndex.compare(":") == 0))
     1167    mIsArray = true;
    22191168}
    22201169
     
    22831232  return mArrayIndex;
    22841233}
     1234
     1235bool ComponentInfo::isArray()
     1236{
     1237  return mIsArray;
     1238}
Note: See TracChangeset for help on using the changeset viewer.