Changeset 13537 for branches/OMEdit/OMEditGUI/Component.cpp
- Timestamp:
- 2012-10-20T20:27:24+02:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OMEdit/OMEditGUI/Component.cpp
r13474 r13537 36 36 #include "Component.h" 37 37 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)38 Component::Component(QString annotation, QString name, QString className, StringHandler::ModelicaClasses type, QString transformation, 39 QPointF position, OMCProxy *pOMCProxy, GraphicsView *pGraphicsView, Component *pParent) 40 40 : QGraphicsItem(pParent), mName(name), mClassName(className), mType(type), mpOMCProxy(pOMCProxy), mpGraphicsView(pGraphicsView), 41 41 mpParentComponent(pParent) … … 67 67 // if type is connector and component is not a library component. 68 68 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*))); 70 70 } 71 71 72 72 /* Called for inheritance annotation instance */ 73 Component _OMC::Component_OMC(QString annotation, QString className, StringHandler::ModelicaClasses type, Component_OMC*pParent)73 Component::Component(QString annotation, QString className, StringHandler::ModelicaClasses type, Component *pParent) 74 74 : QGraphicsItem(pParent), mName(""), mClassName(className), mType(type), mpParentComponent(pParent) 75 75 { … … 85 85 // if type is connector and component is not a library component. 86 86 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*))); 88 88 } 89 89 90 90 /* Called for component annotation instance */ 91 Component _OMC::Component_OMC(QString annotation, QString transformationString, ComponentInfo *pComponentInfo,92 StringHandler::ModelicaClasses type, Component _OMC*pParent)91 Component::Component(QString annotation, QString transformationString, ComponentInfo *pComponentInfo, 92 StringHandler::ModelicaClasses type, Component *pParent) 93 93 : QGraphicsItem(pParent), mpComponentInfo(pComponentInfo), mType(type), mpParentComponent(pParent) 94 94 { … … 107 107 // if type is connector and component is not a library component. 108 108 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*))); 110 110 } 111 111 112 112 /* Used for Library Component */ 113 Component _OMC::Component_OMC(QString annotation, QString className, OMCProxy *pOMCProxy, Component_OMC*pParent)113 Component::Component(QString annotation, QString className, OMCProxy *pOMCProxy, Component *pParent) 114 114 : QGraphicsItem(pParent), mName(className), mClassName(className), mpParentComponent(pParent) 115 115 { … … 127 127 } 128 128 129 void Component _OMC::initialize()129 void Component::initialize() 130 130 { 131 131 mVisible = true; … … 163 163 } 164 164 165 bool Component _OMC::isLibraryComponent()165 bool Component::isLibraryComponent() 166 166 { 167 167 return mIsLibraryComponent; 168 168 } 169 169 170 void Component _OMC::getClassInheritedComponents(bool isRootComponent)170 void Component::getClassInheritedComponents(bool isRootComponent) 171 171 { 172 172 // read the component inheritance … … 191 191 else 192 192 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); 195 195 mpInheritanceList.append(pInheritedComponent); 196 196 } 197 197 } 198 198 199 void Component _OMC::parseAnnotationString(QString annotation)199 void Component::parseAnnotationString(QString annotation) 200 200 { 201 201 // parse the annotation string … … 236 236 shape = shape.mid(QString("Line").length()); 237 237 shape = StringHandler::removeFirstLastBrackets(shape); 238 LineAnnotation _OMC *pLineAnnotation = new LineAnnotation_OMC(shape, this);238 LineAnnotation *pLineAnnotation = new LineAnnotation(shape, this); 239 239 mpShapesList.append(pLineAnnotation); 240 240 } … … 243 243 shape = shape.mid(QString("Polygon").length()); 244 244 shape = StringHandler::removeFirstLastBrackets(shape); 245 PolygonAnnotation _OMC *pPolygonAnnotation = new PolygonAnnotation_OMC(shape, this);245 PolygonAnnotation *pPolygonAnnotation = new PolygonAnnotation(shape, this); 246 246 mpShapesList.append(pPolygonAnnotation); 247 247 } … … 250 250 shape = shape.mid(QString("Rectangle").length()); 251 251 shape = StringHandler::removeFirstLastBrackets(shape); 252 RectangleAnnotation _OMC *pRectangleAnnotation = new RectangleAnnotation_OMC(shape, this);252 RectangleAnnotation *pRectangleAnnotation = new RectangleAnnotation(shape, this); 253 253 mpShapesList.append(pRectangleAnnotation); 254 254 } … … 257 257 shape = shape.mid(QString("Ellipse").length()); 258 258 shape = StringHandler::removeFirstLastBrackets(shape); 259 EllipseAnnotation _OMC *pEllipseAnnotation = new EllipseAnnotation_OMC(shape, this);259 EllipseAnnotation *pEllipseAnnotation = new EllipseAnnotation(shape, this); 260 260 mpShapesList.append(pEllipseAnnotation); 261 261 } … … 268 268 shape = shape.mid(QString("Text").length()); 269 269 shape = StringHandler::removeFirstLastBrackets(shape); 270 TextAnnotation _OMC *pTextAnnotation = new TextAnnotation_OMC(shape, this);270 TextAnnotation *pTextAnnotation = new TextAnnotation(shape, this); 271 271 mpShapesList.append(pTextAnnotation); 272 272 } … … 282 282 } 283 283 284 void Component _OMC::getClassComponents()285 { 286 foreach (Component _OMC*pInheritedComponent, mpInheritanceList)284 void Component::getClassComponents() 285 { 286 foreach (Component *pInheritedComponent, mpInheritanceList) 287 287 { 288 288 pInheritedComponent->getClassComponents(); … … 310 310 { 311 311 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, 313 313 getRootParentComponent()); 314 314 mpComponentsList.append(pComponent); … … 319 319 } 320 320 321 void Component _OMC::createActions()321 void Component::createActions() 322 322 { 323 323 // Properties Action … … 331 331 } 332 332 333 void Component _OMC::createResizerItems()333 void Component::createResizerItems() 334 334 { 335 335 qreal x1, y1, x2, y2; … … 369 369 } 370 370 371 void Component _OMC::getResizerItemsPositions(qreal *x1, qreal *y1, qreal *x2, qreal *y2)371 void Component::getResizerItemsPositions(qreal *x1, qreal *y1, qreal *x2, qreal *y2) 372 372 { 373 373 qreal x11, y11, x22, y22; … … 395 395 } 396 396 397 void Component _OMC::showResizerItems()397 void Component::showResizerItems() 398 398 { 399 399 qreal x1, y1, x2, y2; … … 413 413 } 414 414 415 void Component _OMC::hideResizerItems()415 void Component::hideResizerItems() 416 416 { 417 417 mpBottomLeftResizerItem->setPassive(); … … 421 421 } 422 422 423 QRectF Component _OMC::boundingRect() const423 QRectF Component::boundingRect() const 424 424 { 425 425 qreal left = mpCoOrdinateSystem->getExtent().at(0).x(); … … 430 430 } 431 431 432 void Component _OMC::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)432 void Component::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) 433 433 { 434 434 Q_UNUSED(painter); … … 437 437 } 438 438 439 QString Component _OMC::getName()439 QString Component::getName() 440 440 { 441 441 return mName; 442 442 } 443 443 444 QString Component _OMC::getClassName()444 QString Component::getClassName() 445 445 { 446 446 return mClassName; 447 447 } 448 448 449 StringHandler::ModelicaClasses Component _OMC::getType()449 StringHandler::ModelicaClasses Component::getType() 450 450 { 451 451 return mType; 452 452 } 453 453 454 OMCProxy* Component _OMC::getOMCProxy()454 OMCProxy* Component::getOMCProxy() 455 455 { 456 456 return mpOMCProxy; 457 457 } 458 458 459 GraphicsView* Component _OMC::getGraphicsView()459 GraphicsView* Component::getGraphicsView() 460 460 { 461 461 return mpGraphicsView; 462 462 } 463 463 464 Component _OMC* Component_OMC::getParentComponent()464 Component* Component::getParentComponent() 465 465 { 466 466 return mpParentComponent; 467 467 } 468 468 469 Component _OMC* Component_OMC::getRootParentComponent()470 { 471 Component _OMC*pComponent;469 Component* Component::getRootParentComponent() 470 { 471 Component *pComponent; 472 472 pComponent = this; 473 473 while (pComponent->mpParentComponent) … … 476 476 } 477 477 478 Transformation* Component _OMC::getTransformation()478 Transformation* Component::getTransformation() 479 479 { 480 480 return mpTransformation; 481 481 } 482 482 483 QList<Component _OMC*> Component_OMC::getInheritanceList()483 QList<Component*> Component::getInheritanceList() 484 484 { 485 485 return mpInheritanceList; 486 486 } 487 487 488 ComponentInfo* Component _OMC::getComponentInfo()488 ComponentInfo* Component::getComponentInfo() 489 489 { 490 490 return mpComponentInfo; 491 491 } 492 492 493 QList<ShapeAnnotation _OMC*> Component_OMC::getShapesList()493 QList<ShapeAnnotation*> Component::getShapesList() 494 494 { 495 495 return mpShapesList; 496 496 } 497 497 498 QList<Component _OMC*> Component_OMC::getComponentsList()498 QList<Component*> Component::getComponentsList() 499 499 { 500 500 return mpComponentsList; 501 501 } 502 502 503 void Component _OMC::setOldPosition(QPointF oldPosition)503 void Component::setOldPosition(QPointF oldPosition) 504 504 { 505 505 mOldPosition = oldPosition; 506 506 } 507 507 508 QPointF Component _OMC::getOldPosition()508 QPointF Component::getOldPosition() 509 509 { 510 510 return mOldPosition; 511 511 } 512 512 513 void Component _OMC::setMousePressed(bool On)513 void Component::setMousePressed(bool On) 514 514 { 515 515 mIsMousePressed = On; 516 516 } 517 517 518 void Component _OMC::setComponentFlags()518 void Component::setComponentFlags() 519 519 { 520 520 // set the item flags … … 527 527 } 528 528 529 void Component _OMC::unsetComponentFlags()529 void Component::unsetComponentFlags() 530 530 { 531 531 // unset the item flags … … 538 538 } 539 539 540 void Component _OMC::getExtents(QPointF *pExtent1, QPointF *pExtent2)540 void Component::getExtents(QPointF *pExtent1, QPointF *pExtent2) 541 541 { 542 542 qreal x1, y1, x2, y2; … … 568 568 } 569 569 570 QString Component _OMC::getTransformationAnnotationString()570 QString Component::getTransformationAnnotationString() 571 571 { 572 572 QString annotationString; … … 590 590 } 591 591 592 QString Component _OMC::getPlacementAnnotation()592 QString Component::getPlacementAnnotation() 593 593 { 594 594 // create the placement annotation string … … 600 600 { 601 601 // 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()); 604 604 if (pComponent) 605 605 placementAnnotationString.append(", ").append(pComponent->getTransformationAnnotationString()); … … 612 612 placementAnnotationString.append(", ").append(getTransformationAnnotationString()); 613 613 // 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()); 616 616 if (pComponent) 617 617 placementAnnotationString.append(", ").append(pComponent->getTransformationAnnotationString()); … … 626 626 } 627 627 628 void Component _OMC::updatePlacementAnnotation()628 void Component::updatePlacementAnnotation() 629 629 { 630 630 // Add component annotation. … … 636 636 } 637 637 638 void Component _OMC::applyRotation(qreal angle)638 void Component::applyRotation(qreal angle) 639 639 { 640 640 mpTransformation->setRotateAngle(angle); … … 646 646 } 647 647 648 void Component _OMC::addConnectionDetails(LineAnnotation_OMC*pConnectorLineAnnotation)648 void Component::addConnectionDetails(LineAnnotation *pConnectorLineAnnotation) 649 649 { 650 650 // handle component position, rotation and scale changes … … 659 659 } 660 660 661 void Component _OMC::updateConnection()661 void Component::updateConnection() 662 662 { 663 663 emit componentTransformHasChanged(); 664 664 } 665 665 666 void Component _OMC::prepareResizeShape(ResizerItem *pResizerItem)666 void Component::prepareResizeShape(ResizerItem *pResizerItem) 667 667 { 668 668 hideResizerItems(); … … 699 699 } 700 700 701 void Component _OMC::resizeShape(int index, QPointF newPosition)701 void Component::resizeShape(int index, QPointF newPosition) 702 702 { 703 703 Q_UNUSED(index); … … 741 741 } 742 742 743 void Component _OMC::finishResizeShape()743 void Component::finishResizeShape() 744 744 { 745 745 qreal x1, y1, x2, y2; … … 813 813 } 814 814 815 void Component _OMC::updateShapePosition()815 void Component::updateShapePosition() 816 816 { 817 817 // update the placement annotation of the component … … 820 820 } 821 821 822 void Component _OMC::deleteMe()822 void Component::deleteMe() 823 823 { 824 824 // delete the component from model 825 mpGraphicsView->deleteComponent _OMCObject(this);825 mpGraphicsView->deleteComponentObject(this); 826 826 // remove the component from the scene 827 827 mpGraphicsView->scene()->removeItem(this); … … 831 831 } 832 832 833 void Component _OMC::rotateClockwise()833 void Component::rotateClockwise() 834 834 { 835 835 qreal oldRotation = mpTransformation->getRotateAngle(); … … 845 845 } 846 846 847 void Component _OMC::rotateAntiClockwise()847 void Component::rotateAntiClockwise() 848 848 { 849 849 qreal oldRotation = mpTransformation->getRotateAngle(); … … 863 863 //! @see moveLeft() 864 864 //! @see moveRight() 865 void Component _OMC::moveUp()865 void Component::moveUp() 866 866 { 867 867 mpTransformation->setOrigin(QPointF(mpTransformation->getOrigin().x(), mpTransformation->getOrigin().y() + 1)); … … 876 876 //! @see moveLeft() 877 877 //! @see moveRight() 878 void Component _OMC::moveDown()878 void Component::moveDown() 879 879 { 880 880 mpTransformation->setOrigin(QPointF(mpTransformation->getOrigin().x(), mpTransformation->getOrigin().y() - 1)); … … 889 889 //! @see moveDown() 890 890 //! @see moveRight() 891 void Component _OMC::moveLeft()891 void Component::moveLeft() 892 892 { 893 893 mpTransformation->setOrigin(QPointF(mpTransformation->getOrigin().x() - 1, mpTransformation->getOrigin().y())); … … 902 902 //! @see moveDown() 903 903 //! @see moveLeft() 904 void Component _OMC::moveRight()904 void Component::moveRight() 905 905 { 906 906 mpTransformation->setOrigin(QPointF(mpTransformation->getOrigin().x() + 1, mpTransformation->getOrigin().y())); … … 911 911 } 912 912 913 void Component _OMC::mousePressEvent(QGraphicsSceneMouseEvent *event)913 void Component::mousePressEvent(QGraphicsSceneMouseEvent *event) 914 914 { 915 915 // if user is viewing the component in Icon View … … 937 937 938 938 //! Event when mouse cursor enters component icon. 939 void Component _OMC::hoverEnterEvent(QGraphicsSceneHoverEvent *event)939 void Component::hoverEnterEvent(QGraphicsSceneHoverEvent *event) 940 940 { 941 941 Q_UNUSED(event); … … 946 946 947 947 //! Event when mouse cursor leaves component icon. 948 void Component _OMC::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)948 void Component::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) 949 949 { 950 950 Q_UNUSED(event); … … 954 954 } 955 955 956 void Component _OMC::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)956 void Component::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) 957 957 { 958 958 // if we are viewing some readonly component then don't show the contextmenu … … 960 960 return; 961 961 setSelected(true); 962 Component _OMC*pComponent = getRootParentComponent();962 Component *pComponent = getRootParentComponent(); 963 963 QMenu menu(mpGraphicsView); 964 964 menu.icon(); … … 973 973 } 974 974 975 QVariant Component _OMC::itemChange(GraphicsItemChange change, const QVariant &value)975 QVariant Component::itemChange(GraphicsItemChange change, const QVariant &value) 976 976 { 977 977 QGraphicsItem::itemChange(change, value); … … 1057 1057 } 1058 1058 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 else1092 {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 scene1102 mpGraphicsView->scene()->addItem(this);1103 // if type is diagram then allow connections not for icon view1104 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 connections1140 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 string1152 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 exceptions1169 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 else1188 {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 scene1200 mpGraphicsView->scene()->addItem(this);1201 // if type is diagram then allow connections not for icon view1202 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 shapes1209 foreach(ShapeAnnotation *shape, mpShapesList)1210 {1211 delete shape;1212 }1213 1214 // // delete the list of all components1215 // foreach(Component *component, mpComponentsList)1216 // delete component;1217 1218 // // delete the list of all inherited components1219 // 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 string1247 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 system1256 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 return1265 if (list.size() < 5)1266 return true;1267 // read aspectratio, scale, grid and shapes1268 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 list1275 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 icon1307 //! @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() const1329 {1330 return mRectangle;1331 }1332 1333 void Component::createActions()1334 {1335 // Icon Attributes Action1336 mpIconAttributesAction = new QAction(tr("Attributes"), mpGraphicsView);1337 mpIconAttributesAction->setStatusTip(tr("Shows the item attributes"));1338 connect(mpIconAttributesAction, SIGNAL(triggered()), SLOT(openIconAttributes()));1339 // Icon Properties Action1340 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 View1357 if ((mpGraphicsView->getViewType() == StringHandler::ICON) or (mpGraphicsView->getModelWidget()->getLibraryTreeNode()->isReadOnly()))1358 return;1359 1360 // if component is a connector type then emit the componentClicked signal1361 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 components1367 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 not1373 else if (!mpParentComponent)1374 {1375 setComponentFlags();1376 }1377 1378 // call the mouse press event only if component is the root component1379 // 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 events1396 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 contextmenu1413 if (mpGraphicsView->getModelWidget()->getLibraryTreeNode()->isReadOnly())1414 return;1415 1416 // get the root component, it could be either icon or diagram1417 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 else1466 {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 annotations1493 // if user changes the position with mouse we handle it in mouse events of graphicsview1494 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 view1511 pComponent->updateAnnotationString();1512 }1513 updateAnnotationString();1514 // update connectors annotations that are associated to this component1515 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 #endif1529 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 flags1547 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 flags1558 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 origin1574 annotationString.append("{").append(QString::number(scenePos().x())).append(",");1575 annotationString.append(QString::number(scenePos().y())).append("}, ");1576 // add extent points1577 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 else1590 {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 else1600 {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 rotation1609 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 string1616 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 transformations1623 Component *pComponent;1624 pComponent = mpGraphicsView->getModelWidget()->getDiagramGraphicsView()->getComponentObject(getName());1625 if (pComponent)1626 annotationString.append(pComponent->getTransformationAnnotationString());1627 // then get the icon transformations1628 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 transformations1633 annotationString.append(getTransformationAnnotationString());1634 // then get the icon transformations1635 Component *pComponent;1636 pComponent = mpGraphicsView->getModelWidget()->getIconGraphicsView()->getComponentObject(getName());1637 if (pComponent)1638 annotationString.append(QString(", ").append(pComponent->getTransformationAnnotationString()));1639 }1640 }1641 else1642 {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 updated1649 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 object1657 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 object1672 GraphicsView *pGraphicsView = qobject_cast<GraphicsView*>(const_cast<QObject*>(sender()));1673 // delete the component from model1674 mpGraphicsView->deleteComponentObject(this, update);1675 // remove the component from the scene1676 mpGraphicsView->scene()->removeItem(this);1677 // if the signal is not send by graphicsview then call addclassannotation1678 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 single1688 //component, to do1689 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 scene1699 //mpGraphicsView->scene()->removeItem(this);1700 //if the signal is not send by graphicsview then call addclassannotation1701 // 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 annotation1738 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 annotation1753 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 annotation1769 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 annotation1788 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 else1822 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 else1839 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 inheritance1900 int inheritanceCount = mpOMCProxy->getInheritanceCount(mClassName);1901 for(int i = 1 ; i <= inheritanceCount ; i++)1902 {1903 QString inheritedClass = mpOMCProxy->getNthInheritedClass(mClassName, i);1904 // avoid cycles1905 if (inheritedClass.compare(mClassName) == 0)1906 return;1907 // If the inherited class is one of the builtin type such as Real we can1908 // 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 annotation1915 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 view1923 void Component::getClassComponents()1924 {1925 foreach (Component *pInheritedComponent, mpInheritanceList)1926 {1927 pInheritedComponent->getClassComponents();1928 }1929 // get components1930 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 else1961 {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 view1972 //void Component::getClassComponents(QString className, int type, Component *pParent)1973 //{1974 // // if component type is diagram then1975 // if (type == StringHandler::DIAGRAM)1976 // {1977 // // get the diagram connections1978 // 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 list1986 // 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 can2008 // // 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 cycles2022 // 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 // else2053 // {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 // else2071 // {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 component2095 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 2113 1059 ComponentInfo::ComponentInfo(QString value) 2114 1060 { … … 2133 1079 mCasuality = ""; 2134 1080 mArrayIndex = ""; 1081 mIsArray = false; 2135 1082 parseString(value); 2136 1083 } … … 2217 1164 // read the array index value 2218 1165 mArrayIndex = StringHandler::removeFirstLastCurlBrackets(list.at(11)); 1166 if ((mArrayIndex.compare("n") == 0) || (mArrayIndex.compare(":") == 0)) 1167 mIsArray = true; 2219 1168 } 2220 1169 … … 2283 1232 return mArrayIndex; 2284 1233 } 1234 1235 bool ComponentInfo::isArray() 1236 { 1237 return mIsArray; 1238 }
Note: See TracChangeset
for help on using the changeset viewer.