Changeset 13537 for branches/OMEdit/OMEditGUI/ModelWidgetContainer.cpp
- Timestamp:
- 2012-10-20T20:27:24+02:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OMEdit/OMEditGUI/ModelWidgetContainer.cpp
r13410 r13537 133 133 setIsCreatingConnection(false); 134 134 mIsMovingComponents = false; 135 136 137 138 139 mIsCreatingLine = false;140 mIsCreatingPolygon = false;141 mIsCreatingRectangle = false;142 mIsCreatingEllipse = false;143 mIsCreatingText = false;144 mIsCreatingBitmap = false;145 135 mCustomScale = false; 146 136 createActions(); 147 createMenus();148 137 } 149 138 … … 380 369 else 381 370 annotation = pMainWindow->getOMCProxy()->getIconAnnotation(className); 382 Component _OMC*pComponent;383 pComponent = new Component _OMC(annotation, name, className, type, transformationString, point, pMainWindow->getOMCProxy(), this);371 Component *pComponent; 372 pComponent = new Component(annotation, name, className, type, transformationString, point, pMainWindow->getOMCProxy(), this); 384 373 // unselect all items 385 374 foreach (QGraphicsItem *pItem, items()) … … 391 380 addComponentObject(pComponent); 392 381 else 393 mComponents _OMCList.append(pComponent);394 } 395 396 void GraphicsView::addComponentObject(Component _OMC*pComponent)382 mComponentsList.append(pComponent); 383 } 384 385 void GraphicsView::addComponentObject(Component *pComponent) 397 386 { 398 387 MainWindow *pMainWindow = mpModelWidget->getModelWidgetContainer()->getMainWindow(); … … 403 392 mpModelWidget->getModelicaTextWidget()->getModelicaTextEdit()->document()->setModified(true); 404 393 // add the component to the local list 405 mComponents_OMCList.append(pComponent); 406 } 407 408 void GraphicsView::addComponentoView(QString name, QString className, QString transformationString, QPointF point, bool isConnector, 409 bool addObject, bool diagram) 410 { 411 MainWindow *pMainWindow = mpModelWidget->getModelWidgetContainer()->getMainWindow(); 412 // Check if the icon is already loaded. 413 Component *oldComponent = 0;//pMainWindow->getLibraryTreeWidget()->getComponentObject(className); 414 Component *newComponent; 415 416 // if the item is a connector then we need to get the diagram annotation of it 417 if (diagram) 418 { 419 QString result = pMainWindow->getOMCProxy()->getDiagramAnnotation(className); 420 newComponent = new Component(result, name, className, transformationString, point, isConnector, pMainWindow->getOMCProxy(), this); 421 } 422 else 423 { 424 if (!oldComponent) 425 { 426 LibraryComponent *libComponent; 427 QString result = pMainWindow->getOMCProxy()->getIconAnnotation(className); 428 libComponent = new LibraryComponent(result, className, pMainWindow->getOMCProxy()); 429 // add the component to library widget components lists 430 pMainWindow->getLibraryTreeWidget()->addLibraryComponentObject(libComponent); 431 // create a new component now. 432 newComponent = new Component(result, name, className, transformationString, point, isConnector, pMainWindow->getOMCProxy(), this); 433 } 434 else 435 { 436 newComponent = new Component(oldComponent, name, transformationString, point, isConnector, this); 437 } 438 } 439 if (addObject) 440 addComponentObject(newComponent); 441 else 442 mComponentsList.append(newComponent); 443 } 444 445 void GraphicsView::addComponentObject(Component *component) 446 { 447 MainWindow *pMainWindow = mpModelWidget->getModelWidgetContainer()->getMainWindow(); 448 // Add the component to model in OMC Global Scope. 449 pMainWindow->getOMCProxy()->addComponent(component->getName(), component->getClassName(), mpModelWidget->getLibraryTreeNode()->getNameStructure(), ""); 450 // add the annotations of icon 451 if (component->getIsConnector()) 452 component->updateAnnotationString(true); 453 else 454 component->updateAnnotationString(false); 455 // only update the modelicatext of model if its a diagram view 456 // for icon view the modeltext is updated in updateannotationstring->addclassannotation 457 if (mViewType == StringHandler::DIAGRAM) 458 mpModelWidget->getModelicaTextWidget()->getModelicaTextEdit()->setPlainText(pMainWindow->getOMCProxy()->list(mpModelWidget->getLibraryTreeNode()->getNameStructure())); 459 // add the component to the local list 460 mComponentsList.append(component); 394 mComponentsList.append(pComponent); 461 395 } 462 396 … … 465 399 //! @param update flag is used to check whether we need to update the modelica editor text or not. 466 400 //! @see deleteAllComponentObjects() 467 void GraphicsView::deleteComponent _OMCObject(Component_OMC*pComponent)401 void GraphicsView::deleteComponentObject(Component *pComponent) 468 402 { 469 403 // First Remove the Connector associated to this icon … … 483 417 } 484 418 // remove the icon now from local list 485 mComponents _OMCList.removeOne(pComponent);419 mComponentsList.removeOne(pComponent); 486 420 OMCProxy *pOMCProxy = mpModelWidget->getModelWidgetContainer()->getMainWindow()->getOMCProxy(); 487 421 // delete the component from OMC … … 489 423 } 490 424 491 //! Delete the component and its corresponding connectors from the components list and OMC. 492 //! @param component is the object to be deleted. 493 //! @param update flag is used to check whether we need to update the modelica editor text or not. 494 //! @see deleteAllComponentObjects() 495 void GraphicsView::deleteComponentObject(Component *component, bool update) 496 { 497 // First Remove the Connector associated to this icon 498 int i = 0; 499 while(i != mConnectorsVector.size()) 500 { 501 if((mConnectorsVector[i]->getStartComponent()->getParentComponent()->getName() == component->getName()) or 502 (mConnectorsVector[i]->getEndComponent()->getParentComponent()->getName() == component->getName())) 503 { 504 removeConnector(mConnectorsVector[i], update); 505 i = 0; //Restart iteration if map has changed 506 } 507 else 508 { 509 ++i; 510 } 511 } 512 // remove the icon now from local list 513 mComponentsList.removeOne(component); 514 OMCProxy *pOMCProxy = mpModelWidget->getModelWidgetContainer()->getMainWindow()->getOMCProxy(); 515 // delete the component from OMC 516 pOMCProxy->deleteComponent(component->getName(), mpModelWidget->getLibraryTreeNode()->getNameStructure()); 517 if (update) 518 { 519 mpModelWidget->getModelicaTextWidget()->getModelicaTextEdit()->setPlainText(pOMCProxy->list(mpModelWidget->getLibraryTreeNode()->getNameStructure())); 520 //mpModelWidget->getModelWidgetContainer()->getMainWindow()->getModelBrowserTreeWidget()->updateModelBrowserTreeWidget(); 521 } 522 } 523 524 //! Delete all the component and their corresponding connectors from the model. 525 //! @see deleteComponentObject(Component *component, bool update) 526 void GraphicsView::deleteAllComponentObjects() 527 { 528 mComponentsList.clear(); 529 // foreach (Component *component, mComponentsList) 530 // { 531 // component->deleteMe(false); 532 // } 533 } 534 535 Component_OMC* GraphicsView::getComponent_OMCObject(QString componentName) 536 { 537 foreach (Component_OMC *component, mComponents_OMCList) 425 Component* GraphicsView::getComponentObject(QString componentName) 426 { 427 foreach (Component *component, mComponentsList) 538 428 { 539 429 if (component->getName() == componentName) … … 543 433 } 544 434 545 Component* GraphicsView::getComponentObject(QString componentName)546 {547 foreach (Component *component, mComponentsList)548 {549 if (component->getName() == componentName)550 return component;551 }552 return 0;553 }554 555 435 QString GraphicsView::getUniqueComponentName(QString componentName, int number) 556 436 { 557 437 QString name; 558 438 name = QString(componentName).append(QString::number(number)); 559 foreach (Component _OMC *pComponent, mComponents_OMCList)439 foreach (Component *pComponent, mComponentsList) 560 440 { 561 441 if (pComponent->getName().compare(name, Qt::CaseSensitive) == 0) … … 570 450 bool GraphicsView::checkComponentName(QString componentName) 571 451 { 572 foreach (Component _OMC *pComponent, mComponents_OMCList)452 foreach (Component *pComponent, mComponentsList) 573 453 if (pComponent->getName().compare(componentName, Qt::CaseSensitive) == 0) 574 454 return false; … … 576 456 } 577 457 578 void GraphicsView::addShapeObject(ShapeAnnotation *shape)579 {580 mShapesList.append(shape);581 }582 583 void GraphicsView::deleteShapeObject(ShapeAnnotation *shape)584 {585 mShapesList.removeOne(shape);586 }587 588 void GraphicsView::deleteAllShapesObject()589 {590 mShapesList.clear();591 // foreach (ShapeAnnotation *shape, mShapesList)592 // {593 // shape->deleteMe();594 // }595 }596 597 void GraphicsView::removeAllConnectors()598 {599 mConnectorsVector.clear();600 // int i = 0;601 // while(i != mConnectorsVector.size())602 // {603 // removeConnector(mConnectorsVector[i], false);604 // i = 0; //Restart iteration if map has changed605 // }606 }607 608 458 //! Defines what happens when the mouse is moving in a GraphicsView. 609 459 //! @param event contains information of the mouse moving operation. 610 460 void GraphicsView::mouseMoveEvent(QMouseEvent *event) 611 461 { 612 // don't send mouse move events to items if we are creating something 613 if (!mIsCreatingLine and !mIsCreatingPolygon and !mIsCreatingRectangle 614 and !mIsCreatingEllipse and !mIsCreatingText and !mIsCreatingBitmap) 615 { 616 QGraphicsView::mouseMoveEvent(event); 617 } 462 QGraphicsView::mouseMoveEvent(event); 618 463 //If creating connector, the end port shall be updated to the mouse position. 619 464 if (isCreatingConnection()) … … 621 466 mpConnectionLineAnnotation->updateEndPoint(mapToScene(event->pos())); 622 467 mpConnectionLineAnnotation->update(); 623 }624 //If creating line shape, the end points shall be updated to the mouse position.625 else if (mIsCreatingLine)626 {627 mpLineShape->updateEndPoint(mapToScene(event->pos()));628 mpLineShape->update();629 }630 //If creating polygon shape, the end points shall be updated to the mouse position.631 else if (mIsCreatingPolygon)632 {633 mpPolygonShape->updateEndPoint(mapToScene(event->pos()));634 mpPolygonShape->update();635 }636 //If creating rectangle shape, the end points shall be updated to the mouse position.637 else if (mIsCreatingRectangle)638 {639 mpRectangleShape->updateEndPoint(mapToScene(event->pos()));640 mpRectangleShape->update();641 }642 //If creating ellipse shape, the end points shall be updated to the mouse position.643 else if (mIsCreatingEllipse)644 {645 mpEllipseShape->updateEndPoint(mapToScene(event->pos()));646 mpEllipseShape->update();647 }648 //If creating text shape, the end points shall be updated to the mouse position.649 else if (mIsCreatingText)650 {651 mpTextShape->updateEndPoint(mapToScene(event->pos()));652 mpTextShape->update();653 }654 //If creating bitmap shape, the end points shall be updated to the mouse position.655 else if (mIsCreatingBitmap)656 {657 mpBitmapShape->updateEndPoint(mapToScene(event->pos()));658 mpBitmapShape->update();659 468 } 660 469 } … … 670 479 mpConnectionLineAnnotation->addPoint(mapToScene(event->pos())); 671 480 } 672 // if left button presses and we are starting to create a Line673 else if ((event->button() == Qt::LeftButton) && pMainWindow->getLineAction()->isChecked())674 {675 // if we are starting to create a line then create line object and add to graphicsview676 createLineShape(mapToScene(event->pos()));677 }678 // if left button presses and we are starting to create a Rectangle679 else if ((event->button() == Qt::LeftButton) && pMainWindow->getRectangleAction()->isChecked())680 {681 // if we are starting to create a rectangle then create rectangle object and add to graphicsview682 createRectangleShape(mapToScene(event->pos()));683 }684 // if left button presses and we are starting to create an Ellipse685 else if ((event->button() == Qt::LeftButton) && pMainWindow->getEllipseAction()->isChecked())686 {687 // if we are starting to create a rectangle then create rectangle object and add to graphicsview688 createEllipseShape(mapToScene(event->pos()));689 }690 // if left button presses and we are starting to create a Polygon691 else if ((event->button() == Qt::LeftButton) && pMainWindow->getPolygonAction()->isChecked())692 {693 // if we are starting to create a polygon then create line object and add to graphicsview694 createPolygonShape(mapToScene(event->pos()));695 }696 // if left button presses and we are starting to create a Text697 else if ((event->button() == Qt::LeftButton) && pMainWindow->getTextAction()->isChecked())698 {699 // if we are starting to create a text then create text object and add to graphicsview700 createTextShape(mapToScene(event->pos()));701 }702 // if left button presses and we are starting to create a BITMAP703 else if ((event->button() == Qt::LeftButton) && pMainWindow->getBitmapAction()->isChecked())704 {705 // if we are starting to create a BITMAP then create BITMAP object and add to graphicsview706 createBitmapShape(mapToScene(event->pos()));707 }708 481 // if left button presses and we are not creating a connector 709 482 else if ((event->button() == Qt::LeftButton)) … … 712 485 mIsMovingComponents = true; 713 486 // save the position of all components 714 foreach (Component _OMC *pComponent, mComponents_OMCList)487 foreach (Component *pComponent, mComponentsList) 715 488 { 716 489 pComponent->setOldPosition(pComponent->pos()); … … 718 491 } 719 492 } 720 /* don't send mouse press events to items if we are creating something, only send them if creating a connector 721 because for connector we need to select end port */ 722 if (!mIsCreatingLine and !mIsCreatingPolygon and !mIsCreatingRectangle and !mIsCreatingEllipse 723 and !mIsCreatingText and !mIsCreatingBitmap) 724 { 725 QGraphicsView::mousePressEvent(event); 726 } 493 QGraphicsView::mousePressEvent(event); 727 494 } 728 495 … … 733 500 mIsMovingComponents = false; 734 501 // if component position is changed then update annotations 735 foreach (Component _OMC *pComponent, mComponents_OMCList)502 foreach (Component *pComponent, mComponentsList) 736 503 { 737 504 if (pComponent->getOldPosition() != pComponent->pos()) … … 739 506 pComponent->updatePlacementAnnotation(); 740 507 // if there are any connectors associated to component update their annotations as well. 741 foreach (LineAnnotation _OMC*pConnectionLineAnnotation, mConnectionsList)508 foreach (LineAnnotation *pConnectionLineAnnotation, mConnectionsList) 742 509 { 743 510 if ((pConnectionLineAnnotation->getStartComponent()->getParentComponent() == pComponent) || … … 759 526 void GraphicsView::mouseDoubleClickEvent(QMouseEvent *event) 760 527 { 761 MainWindow *pMainWindow = mpModelWidget->getModelWidgetContainer()->getMainWindow();762 if (mIsCreatingLine)763 {764 // finish creating the line765 mIsCreatingLine = false;766 // add the line to shapes list767 addShapeObject(mpLineShape);768 mpLineShape->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);769 mpLineShape->drawRectangleCornerItems();770 // make the toolbar button of line unchecked771 pMainWindow->getLineAction()->setChecked(false);772 }773 else if (mIsCreatingPolygon)774 {775 // finish creating the line776 mIsCreatingPolygon = false;777 // add the line to shapes list778 addShapeObject(mpPolygonShape);779 mpPolygonShape->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);780 mpPolygonShape->drawRectangleCornerItems();781 // make the toolbar button of line unchecked782 pMainWindow->getPolygonAction()->setChecked(false);783 }784 528 QGraphicsView::mouseDoubleClickEvent(event); 785 529 } … … 898 642 mpPasteComponentAction->setStatusTip(tr("Copy the item")); 899 643 mpPasteComponentAction->setDisabled(true); 900 connect(mpPasteComponentAction, SIGNAL(triggered()), SLOT(pasteComponent()));644 //connect(mpPasteComponentAction, SIGNAL(triggered()), SLOT(pasteComponent())); 901 645 //mpPasteComponentAction->setShortcut(QKeySequence("Ctrl+c")); 902 }903 904 void GraphicsView::createMenus()905 {906 907 }908 909 //pasting the required copied component or a selection in the present view910 //non functional currently, only works for a single component911 void GraphicsView::pasteComponent()912 {913 914 QClipboard *clipboard = QApplication::clipboard();915 916 if(!clipboard->text().isEmpty())917 {918 //GraphicsView *pGraphicsView = qobject_cast<GraphicsView*>(const_cast<QObject*>(sender()));919 Component *oldComponent = getComponentObject(clipboard->text());920 Component *newComponent;921 QString name = getUniqueComponentName(oldComponent->getName().toLower());922 923 //QPointF point;924 QPointF point (mapToScene(pos()));925 926 //point= QPointF((pos().x()) +1.0 ,(pos().y()) +1.0);927 //newComponent = new Component(oldComponent,name,point,oldComponent->getIsConnector(),this);928 // remove the component from the scene929 //mpGraphicsView->scene()->removeItem(this);930 // if the signal is not send by graphicsview then call addclassannotation931 //if (!pGraphicsView)932 // {933 // if (mpGraphicsView->mIconType == StringHandler::ICON)934 // mpGraphicsView->addClassAnnotation();935 // }936 // delete(this);937 //addComponentObject(newComponent);938 }939 else940 {941 return ;942 }943 646 } 944 647 … … 947 650 GraphicsViewProperties *pGraphicsViewProperties = new GraphicsViewProperties(this); 948 651 pGraphicsViewProperties->show(); 949 }950 951 void GraphicsView::createLineShape(QPointF point)952 {953 if (mpModelWidget->getLibraryTreeNode()->isReadOnly())954 return;955 956 if (!mIsCreatingLine)957 {958 mIsCreatingLine = true;959 mpLineShape = new LineAnnotation(this);960 mpLineShape->addPoint(point);961 mpLineShape->addPoint(point);962 scene()->addItem(mpLineShape);963 }964 // if we are already creating a line then only add one point.965 else966 {967 mpLineShape->addPoint(point);968 }969 }970 971 void GraphicsView::createPolygonShape(QPointF point)972 {973 if (mpModelWidget->getLibraryTreeNode()->isReadOnly())974 return;975 976 if (!mIsCreatingPolygon)977 {978 mIsCreatingPolygon = true;979 mpPolygonShape = new PolygonAnnotation(this);980 mpPolygonShape->addPoint(point);981 mpPolygonShape->addPoint(point);982 mpPolygonShape->addPoint(point);983 scene()->addItem(mpPolygonShape);984 }985 // if we are already creating a polygon then only add one point.986 else987 {988 mpPolygonShape->addPoint(point);989 }990 }991 992 void GraphicsView::createRectangleShape(QPointF point)993 {994 if (mpModelWidget->getLibraryTreeNode()->isReadOnly())995 return;996 997 if (!mIsCreatingRectangle)998 {999 mIsCreatingRectangle = true;1000 mpRectangleShape = new RectangleAnnotation(this);1001 mpRectangleShape->addPoint(point);1002 mpRectangleShape->addPoint(point);1003 scene()->addItem(mpRectangleShape);1004 }1005 // if we are already creating a rectangle then simply finish creating it.1006 else1007 {1008 // finish creating the rectangle1009 mIsCreatingRectangle = false;1010 // add the line to shapes list1011 addShapeObject(mpRectangleShape);1012 mpRectangleShape->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);1013 mpRectangleShape->drawRectangleCornerItems();1014 // make the toolbar button of line unchecked1015 mpModelWidget->getModelWidgetContainer()->getMainWindow()->getRectangleAction()->setChecked(false);1016 }1017 }1018 1019 void GraphicsView::createEllipseShape(QPointF point)1020 {1021 if (mpModelWidget->getLibraryTreeNode()->isReadOnly())1022 return;1023 1024 if (!mIsCreatingEllipse)1025 {1026 mIsCreatingEllipse = true;1027 mpEllipseShape = new EllipseAnnotation(this);1028 mpEllipseShape->addPoint(point);1029 mpEllipseShape->addPoint(point);1030 scene()->addItem(mpEllipseShape);1031 }1032 // if we are already creating a rectangle then simply finish creating it.1033 else1034 {1035 // finish creating the rectangle1036 mIsCreatingEllipse = false;1037 // add the line to shapes list1038 addShapeObject(mpEllipseShape);1039 mpEllipseShape->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);1040 mpEllipseShape->drawRectangleCornerItems();1041 // make the toolbar button of line unchecked1042 mpModelWidget->getModelWidgetContainer()->getMainWindow()->getEllipseAction()->setChecked(false);1043 }1044 }1045 1046 void GraphicsView::createTextShape(QPointF point)1047 {1048 if (mpModelWidget->getLibraryTreeNode()->isReadOnly())1049 return;1050 1051 if (!mIsCreatingText)1052 {1053 mIsCreatingText = true;1054 mpTextShape = new TextAnnotation(this);1055 mpTextShape->addPoint(point);1056 mpTextShape->addPoint(point);1057 scene()->addItem(mpTextShape);1058 }1059 // if we are already creating a text then simply finish creating it.1060 else1061 {1062 // finish creating the text1063 mIsCreatingText = false;1064 // add the line to shapes list1065 addShapeObject(mpTextShape);1066 mpTextShape->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);1067 mpTextShape->drawRectangleCornerItems();1068 // make the toolbar button of line unchecked1069 mpModelWidget->getModelWidgetContainer()->getMainWindow()->getTextAction()->setChecked(false);1070 // open the text properties dialog1071 mpTextWidget = new TextWidget(mpTextShape, mpModelWidget->getModelWidgetContainer()->getMainWindow());1072 mpTextWidget->show();1073 }1074 }1075 1076 void GraphicsView::createBitmapShape(QPointF point)1077 {1078 if (mpModelWidget->getLibraryTreeNode()->isReadOnly())1079 return;1080 1081 if (!mIsCreatingBitmap)1082 {1083 //If model doesnt exist, then alert the user...1084 if(mpModelWidget->getLibraryTreeNode()->getFileName().isEmpty())1085 {1086 QMessageBox *msgBox = new QMessageBox(mpModelWidget->getModelWidgetContainer()->getMainWindow());1087 msgBox->setWindowTitle(QString(Helper::applicationName).append(" - Information"));1088 msgBox->setIcon(QMessageBox::Warning);1089 msgBox->setText(QString("The class needs to be saved before you can insert a bitmap."));1090 msgBox->setStandardButtons(QMessageBox::Ok);1091 msgBox->setDefaultButton(QMessageBox::Ok);1092 msgBox->exec();1093 mpModelWidget->getModelWidgetContainer()->getMainWindow()->getBitmapAction()->setChecked(false);1094 return;1095 }1096 mIsCreatingBitmap = true;1097 mpBitmapShape = new BitmapAnnotation(this);1098 mpBitmapShape->addPoint(point);1099 mpBitmapShape->addPoint(point);1100 scene()->addItem(mpBitmapShape);1101 }1102 else1103 {1104 // finish creating the bitmap1105 mIsCreatingBitmap = false;1106 // add the line to shapes list1107 addShapeObject(mpBitmapShape);1108 mpBitmapShape->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);1109 mpBitmapShape->drawRectangleCornerItems();1110 // make the toolbar button of line unchecked1111 mpModelWidget->getModelWidgetContainer()->getMainWindow()->getBitmapAction()->setChecked(false);1112 mpBitmapWidget = new BitmapWidget(mpBitmapShape, mpModelWidget->getModelWidgetContainer()->getMainWindow());1113 mpBitmapWidget->show();1114 }1115 652 } 1116 653 … … 1149 686 } 1150 687 1151 void GraphicsView::addConnection(Component _OMC*pComponent)688 void GraphicsView::addConnection(Component *pComponent) 1152 689 { 1153 690 // When clicking the start component … … 1155 692 { 1156 693 QPointF startPos = pComponent->mapToScene(pComponent->boundingRect().center()); 1157 mpConnectionLineAnnotation = new LineAnnotation _OMC(pComponent, this);694 mpConnectionLineAnnotation = new LineAnnotation(pComponent, this); 1158 695 setIsCreatingConnection(true); 1159 696 // if component is a connector 1160 Component _OMC*pRootParentComponent = pComponent->getRootParentComponent();697 Component *pRootParentComponent = pComponent->getRootParentComponent(); 1161 698 if (pRootParentComponent) 1162 699 pRootParentComponent->addConnectionDetails(mpConnectionLineAnnotation); … … 1171 708 { 1172 709 mpConnectionLineAnnotation->setEndComponent(pComponent); 1173 Component _OMC*pStartComponent = mpConnectionLineAnnotation->getStartComponent();710 Component *pStartComponent = mpConnectionLineAnnotation->getStartComponent(); 1174 711 MainWindow *pMainWindow = mpModelWidget->getModelWidgetContainer()->getMainWindow(); 1175 712 if (pStartComponent == pComponent) … … 1180 717 return; 1181 718 } 1182 QString startComponentName, endComponentName;719 bool showConnectionArrayDialog = false; 1183 720 if (pStartComponent->getParentComponent()) 1184 startComponentName = QString(pStartComponent->getParentComponent()->getName()).append(".").append(pStartComponent->getComponentInfo()->getName()); 1185 else 1186 startComponentName = pStartComponent->getName(); 721 if ((pStartComponent->getComponentInfo()->getArrayIndex().compare("n") == 0) || (pStartComponent->getComponentInfo()->getArrayIndex().compare(":") == 0)) 722 showConnectionArrayDialog = true; 1187 723 if (pComponent->getParentComponent()) 1188 endComponentName = QString(pComponent->getParentComponent()->getName()).append(".").append(pComponent->getComponentInfo()->getName()); 1189 else 1190 endComponentName = pComponent->getName(); 1191 createConnection(startComponentName, endComponentName); 1192 } 1193 } 1194 1195 //! Begins creation of connector or complete creation of connector depending on the mIsCreatingConnector flag. 1196 //! @param pComponent is a pointer to the clicked Component, either start or end depending on the mIsCreatingConnector flag. 1197 void GraphicsView::addConnector(Component *pComponent) 1198 { 1199 //When clicking start port 1200 if (!mIsCreatingConnection) 1201 { 1202 QPointF startPos = pComponent->mapToScene(pComponent->boundingRect().center()); 1203 mpConnector = new Connector(pComponent, this); 1204 scene()->addItem(mpConnector); 1205 mIsCreatingConnection = true; 1206 //if component is a connector 1207 if (pComponent->getParentComponent()) 1208 pComponent->getParentComponent()->addConnector(mpConnector); 1209 else 1210 pComponent->addConnector(mpConnector); 1211 mpConnector->setStartComponent(pComponent); 1212 mpConnector->addPoint(startPos); 1213 mpConnector->addPoint(startPos); 1214 mpConnector->drawConnector(); 1215 } 1216 // When clicking end port 1217 else 1218 { 1219 Component *pStartComponent = mpConnector->getStartComponent(); 1220 QString startIconName, startIconCompName, endIconName, endIconCompName; 1221 if (pStartComponent->getParentComponent()) 724 if ((pComponent->getComponentInfo()->getArrayIndex().compare("n") == 0) || (pComponent->getComponentInfo()->getArrayIndex().compare(":") == 0)) 725 showConnectionArrayDialog = true; 726 if (showConnectionArrayDialog) 1222 727 { 1223 startIconName = QString(pStartComponent->getParentComponent()->getName()).append("."); 1224 startIconCompName = pStartComponent->getComponentInfo()->getName(); 728 ConnectionArray *pConnectionArray = new ConnectionArray(this, mpConnectionLineAnnotation, 729 getModelWidget()->getModelWidgetContainer()->getMainWindow()); 730 pConnectionArray->show(); 1225 731 } 1226 732 else 1227 733 { 1228 startIconCompName = pStartComponent->getName(); 1229 } 1230 if (pComponent->getParentComponent()) 1231 { 1232 endIconName = QString(pComponent->getParentComponent()->getName()).append("."); 1233 endIconCompName = pComponent->getComponentInfo()->getName(); 1234 } 1235 else 1236 { 1237 endIconCompName = pComponent->getName(); 1238 } 1239 1240 MainWindow *pMainWindow = mpModelWidget->getModelWidgetContainer()->getMainWindow(); 1241 QList<ComponentInfo*> startcomponents = pStartComponent->getParentComponent()->getChildComponentInfo(); 1242 if (startcomponents.isEmpty()) 1243 { 1244 startcomponents = pMainWindow->getOMCProxy()->getComponents(pStartComponent->getParentComponent()->getClassName()); 1245 } 1246 //to check whether the component is an array of connectors 1247 foreach(ComponentInfo *pComponentInfo , startcomponents) 1248 { 1249 //to check whether the component is an array of connectors 1250 if (pComponentInfo->getName() == startIconCompName) 1251 { 1252 // if (pComponentInfo->getIndexValue() != -1) 1253 // { 1254 // mpConnector->setStartConnectorisArray(true); 1255 // } 1256 } 1257 } 1258 1259 QList<ComponentInfo*> endcomponents = pComponent->getParentComponent()->getChildComponentInfo(); 1260 if(endcomponents.isEmpty()) 1261 { 1262 endcomponents = pMainWindow->getOMCProxy()->getComponents(pComponent->getParentComponent()->getClassName()); 1263 } 1264 //to check whether the component is an array of connectors 1265 foreach(ComponentInfo *pComponentInfo , endcomponents) 1266 { 1267 if (pComponentInfo->getName() == endIconCompName) 1268 { 1269 // if (pComponentInfo->getIndexValue() != -1) 1270 // { 1271 // mpConnector->setEndConnectorisArray(true); 1272 // } 1273 } 1274 } 1275 //if atleast one of the port is an array of connectors 1276 if (mpConnector->getEndConnectorisArray() || mpConnector->getStartConnectorisArray()) 1277 { 1278 mpConnector->setEndComponent(pComponent); 1279 //shows the connector array menu for adding the index for the array 1280 mpConnector->mpConnectorArrayMenu->show(); 1281 } 1282 else 1283 { 1284 createConnection(pStartComponent, QString(startIconName).append(startIconCompName), 1285 pComponent, QString(endIconName).append(endIconCompName)); 734 QString startComponentName, endComponentName; 735 if (pStartComponent->getParentComponent()) 736 startComponentName = QString(pStartComponent->getParentComponent()->getName()).append(".").append(pStartComponent->getComponentInfo()->getName()); 737 else 738 startComponentName = pStartComponent->getName(); 739 if (pComponent->getParentComponent()) 740 endComponentName = QString(pComponent->getParentComponent()->getName()).append(".").append(pComponent->getComponentInfo()->getName()); 741 else 742 endComponentName = pComponent->getName(); 743 createConnection(startComponentName, endComponentName); 1286 744 } 1287 745 } … … 1298 756 { 1299 757 setIsCreatingConnection(false); 1300 Component_OMC *pEndComponent = mpConnectionLineAnnotation->getEndComponent(); 758 mpConnectionLineAnnotation->setStartComponentName(startComponentName); 759 mpConnectionLineAnnotation->setEndComponentName(endComponentName); 760 Component *pEndComponent = mpConnectionLineAnnotation->getEndComponent(); 1301 761 if (pEndComponent->getParentComponent()) 1302 762 pEndComponent->getParentComponent()->addConnectionDetails(mpConnectionLineAnnotation); … … 1320 780 } 1321 781 1322 void GraphicsView::createConnection(Component *pStartComponent, QString startIconCompName, Component *pComponent, QString endIconCompName)1323 {1324 MainWindow *pMainWindow = mpModelWidget->getModelWidgetContainer()->getMainWindow();1325 // If both components are same1326 if (pStartComponent == pComponent)1327 {1328 removeConnector();1329 pMainWindow->getProblemsWidget()->addGUIProblem(new ProblemItem("", false, 0, 0, 0, 0,1330 GUIMessages::getMessage(GUIMessages::SAME_COMPONENT_CONNECT),1331 Helper::scriptingKind, Helper::errorLevel, 0,1332 pMainWindow->getProblemsWidget()->mpProblem));1333 }1334 else1335 {1336 if (pMainWindow->getOMCProxy()->addConnection(startIconCompName, endIconCompName, mpModelWidget->getLibraryTreeNode()->getNameStructure(), ""))1337 {1338 // Check if both components connected are compatible or not.1339 if (pMainWindow->getOMCProxy()->instantiateModelSucceeds(mpModelWidget->getLibraryTreeNode()->getNameStructure()))1340 {1341 mIsCreatingConnection = false;1342 QPointF newPos = pComponent->mapToScene(pComponent->boundingRect().center());1343 mpConnector->updateEndPoint(newPos);1344 if (pComponent->getParentComponent())1345 pComponent->getParentComponent()->addConnector(mpConnector);1346 else1347 pComponent->addConnector(mpConnector);1348 mpConnector->setEndComponent(pComponent);1349 // update the last point to the center of component1350 mpConnector->updateEndPoint(pComponent->boundingRect().center());1351 mpConnector->drawConnector(false);1352 mConnectorsVector.append(mpConnector);1353 // add the connection annotation to OMC1354 mpConnector->updateConnectionAnnotationString();1355 mpModelWidget->getModelicaTextWidget()->getModelicaTextEdit()->setPlainText(pMainWindow->getOMCProxy()->list(mpModelWidget->getLibraryTreeNode()->getNameStructure()));1356 }1357 else1358 {1359 removeConnector();1360 // since this is an on purpose connection delete so dont make model unsaved :)1361 // so to avoid model unsaving we have to blovk signals of Modelica editor1362 mpModelWidget->getModelicaTextWidget()->blockSignals(true);1363 // remove the connection from model1364 pMainWindow->getOMCProxy()->deleteConnection(startIconCompName, endIconCompName, mpModelWidget->getLibraryTreeNode()->getNameStructure());1365 mpModelWidget->getModelicaTextWidget()->blockSignals(false);1366 }1367 }1368 }1369 }1370 //add connector function in case atleast one port is an array1371 //! @param pStartComponent is1372 void GraphicsView::addConnectorForArray(Component *pStartComponent,Component *pEndComponent ,int startindex , int endindex)1373 {1374 //if user pressed cancel in the array menu, remove the connection1375 if(startindex==-1 && endindex==-1)1376 {1377 removeConnector();1378 }1379 1380 else1381 {1382 QString startIndexStr = QString::number(startindex);1383 QString endIndexStr = QString::number(endindex);1384 mpConnector->mpConnectorArrayMenu->setStartConnectorIndex(startIndexStr);1385 mpConnector->mpConnectorArrayMenu->setEndConnectorIndex(endIndexStr);1386 QString startIconName, startIconCompName, endIconName, endIconCompName;1387 // appending the indices if it is an array of connectors;1388 if (pStartComponent->getParentComponent())1389 {1390 startIconName = QString(pStartComponent->getParentComponent()->getName()).append(".");1391 if(!mpConnector->getStartConnectorisArray())1392 startIconCompName = pStartComponent->getComponentInfo()->getName();1393 else1394 startIconCompName = pStartComponent->getComponentInfo()->getName() + "[" + mpConnector->mpConnectorArrayMenu->getStartConnectorIndex() + "]";1395 }1396 else1397 {1398 if(!mpConnector->getStartConnectorisArray())1399 startIconCompName = pStartComponent->getName();1400 else1401 startIconCompName = pStartComponent->getName() + "[" + startIndexStr + "]";1402 }1403 1404 if (pEndComponent->getParentComponent())1405 {1406 endIconName = QString(pEndComponent->getParentComponent()->getName()).append(".");1407 if(!mpConnector->getEndConnectorisArray())1408 endIconCompName = pEndComponent->getComponentInfo()->getName();1409 else1410 endIconCompName = pEndComponent->getComponentInfo()->getName() + "[" + mpConnector->mpConnectorArrayMenu->getEndConnectorIndex() + "]";1411 }1412 else1413 {1414 1415 if(!mpConnector->getEndConnectorisArray())1416 endIconCompName = pEndComponent->getName();1417 else1418 endIconCompName = pEndComponent->getName() + "[" + endIndexStr + "]";1419 }1420 1421 createConnection(pStartComponent, QString(startIconName).append(startIconCompName),1422 pEndComponent, QString(endIconName).append(endIconCompName));1423 1424 }1425 }1426 1427 782 //! Removes the current connecting connector from the model. 1428 783 void GraphicsView::removeConnection() … … 1452 807 } 1453 808 1454 //! Removes the current connecting connector from the model.1455 void GraphicsView::removeConnector()1456 {1457 if (mIsCreatingConnection)1458 {1459 scene()->removeItem(mpConnector);1460 delete mpConnector;1461 mIsCreatingConnection = false;1462 }1463 else1464 {1465 int i = 0;1466 while(i != mConnectorsVector.size())1467 {1468 if(mConnectorsVector[i]->isActive())1469 {1470 removeConnector(mConnectorsVector[i]);1471 i = 0; //Restart iteration if map has changed1472 }1473 else1474 {1475 ++i;1476 }1477 }1478 }1479 }1480 1481 809 //! Removes the connector from the model. 1482 810 //! @param pConnector is a pointer to the connector to remove. 1483 void GraphicsView::removeConnection(LineAnnotation _OMC*pConnection)811 void GraphicsView::removeConnection(LineAnnotation *pConnection) 1484 812 { 1485 813 bool doDelete = false; … … 1496 824 if (doDelete) 1497 825 { 1498 // If GUI delete is successful then remove the connection from omc as well. 1499 QString startComponentName, endComponentName; 1500 Component_OMC *pStartComponent, *pEndComponent; 1501 pStartComponent = pConnection->getStartComponent(); 1502 pEndComponent = pConnection->getEndComponent(); 1503 if (pStartComponent->getParentComponent()) 1504 startComponentName = QString(pStartComponent->getParentComponent()->getName()).append(".").append(pStartComponent->getComponentInfo()->getName()); 1505 else 1506 startComponentName = pStartComponent->getName(); 1507 if (pEndComponent->getParentComponent()) 1508 endComponentName = QString(pEndComponent->getParentComponent()->getName()).append(".").append(pEndComponent->getComponentInfo()->getName()); 1509 else 1510 endComponentName = pEndComponent->getName(); 1511 // delete Connection 1512 deleteConnection(startComponentName, endComponentName); 826 // If GUI delete is successful then delete the connection from omc as well. 827 deleteConnection(pConnection->getStartComponentName(), pConnection->getEndComponentName()); 1513 828 // delete the connector object 1514 829 pConnection->deleteLater(); 1515 830 // remove connector object from local connector vector 1516 831 mConnectionsList.removeAt(i); 1517 }1518 }1519 1520 //! Removes the connector from the model.1521 //! @param pConnector is a pointer to the connector to remove.1522 void GraphicsView::removeConnector(Connector *pConnector, bool update)1523 {1524 bool doDelete = false;1525 int i;1526 1527 for(i = 0; i != mConnectorsVector.size(); ++i)1528 {1529 if(mConnectorsVector[i] == pConnector)1530 {1531 scene()->removeItem(pConnector);1532 doDelete = true;1533 break;1534 }1535 if(mConnectorsVector.empty())1536 break;1537 }1538 if (doDelete)1539 {1540 // If GUI delete is successful then remove the connection from omc as well.1541 QString startIconName, startIconCompName, endIconName, endIconCompName;1542 if (pConnector->getStartComponent()->getParentComponent())1543 {1544 startIconName = QString(pConnector->getStartComponent()->getParentComponent()->getName()).append(".");1545 if(!pConnector->getStartConnectorisArray())1546 startIconCompName =pConnector->getStartComponent()->getComponentInfo()->getName();1547 else1548 startIconCompName = pConnector->getStartComponent()->getComponentInfo()->getName() + "[" + pConnector->mpConnectorArrayMenu->getStartConnectorIndex() + "]";1549 }1550 else1551 {1552 startIconCompName = pConnector->getStartComponent()->getName();1553 if(!pConnector->getStartConnectorisArray())1554 startIconCompName =pConnector->getStartComponent()->getName();1555 else1556 startIconCompName = pConnector->getStartComponent()->getName() + "[" + pConnector->mpConnectorArrayMenu->getStartConnectorIndex() + "]";1557 }1558 if (pConnector->getEndComponent()->getParentComponent())1559 {1560 endIconName = QString(pConnector->getEndComponent()->getParentComponent()->getName()).append(".");1561 if(!pConnector->getEndConnectorisArray())1562 endIconCompName = pConnector->getEndComponent()->getComponentInfo()->getName();1563 else1564 endIconCompName = pConnector->getEndComponent()->getComponentInfo()->getName() + "[" + pConnector->mpConnectorArrayMenu->getEndConnectorIndex() + "]";1565 }1566 else1567 {1568 if(!pConnector->getEndConnectorisArray())1569 endIconCompName = pConnector->getEndComponent()->getName();1570 else1571 endIconCompName = pConnector->getEndComponent()->getName() + "[" + pConnector->mpConnectorArrayMenu->getEndConnectorIndex() + "]";1572 }1573 // delete Connection1574 //deleteConnection(QString(startIconName).append(startIconCompName), QString(endIconName).append(endIconCompName), update);1575 // delete the connector object1576 delete pConnector;1577 // remove connector object from local connector vector1578 mConnectorsVector.remove(i);1579 832 } 1580 833 } … … 1629 882 { 1630 883 //Select all components 1631 foreach (Component _OMC *pComponent, mComponents_OMCList)884 foreach (Component *pComponent, mComponentsList) 1632 885 { 1633 886 pComponent->setSelected(true); 1634 }1635 // Select all connectors1636 foreach (Connector *connector, mConnectorsVector)1637 {1638 // just make one line of connector selected, it will make the whole connector selected1639 foreach (ConnectorLine *connectorLine, connector->mpLines)1640 {1641 connectorLine->setSelected(true);1642 break;1643 }1644 }1645 // select all shapes like line, rectangle, polygon etc...1646 foreach (ShapeAnnotation *pShape, mShapesList)1647 {1648 pShape->setSelected(true);1649 887 } 1650 888 } … … 1685 923 annotationString.append(", grid=").append("{").append(QString::number(grid.x())).append(", ").append(QString::number(grid.y())).append("})"); 1686 924 // add the graphics annotations 1687 if (mShapesList.size() > 0)1688 {1689 annotationString.append(", graphics={");1690 foreach (ShapeAnnotation *shape, mShapesList)1691 {1692 annotationString.append(shape->getShapeAnnotation());1693 if (counter < mShapesList.size() - 1)1694 annotationString.append(",");1695 counter++;1696 }1697 annotationString.append("}");1698 }925 // if (mShapesList.size() > 0) 926 // { 927 // annotationString.append(", graphics={"); 928 // foreach (ShapeAnnotation *shape, mShapesList) 929 // { 930 // annotationString.append(shape->getShapeAnnotation()); 931 // if (counter < mShapesList.size() - 1) 932 // annotationString.append(","); 933 // counter++; 934 // } 935 // annotationString.append("}"); 936 // } 1699 937 annotationString.append(")"); 1700 938 … … 1885 1123 mpLatestNewsLabel = new Label(tr("Latest News")); 1886 1124 mpLatestNewsLabel->setFont(QFont("", Helper::headingFontSize)); 1125 mpNoLatestNewsLabel = new Label; 1887 1126 mpLatestNewsListWidget = new QListWidget; 1888 1127 mpLatestNewsListWidget->setObjectName("LatestNewsList"); … … 1894 1133 mpLatestNewsListWidget->setIconSize(Helper::iconSize); 1895 1134 mpLatestNewsListWidget->setCurrentRow(0, QItemSelectionModel::Select); 1135 mpReloadLatestNewsButton = new QPushButton(tr("Reload")); 1136 connect(mpReloadLatestNewsButton, SIGNAL(clicked()), SLOT(addLatestNewsListItems())); 1896 1137 mpVisitWebsiteLabel = new Label(tr("For more details visit our website <u><a href=\"www.openmodelica.org\">www.openmodelica.org</a></u>")); 1897 1138 mpVisitWebsiteLabel->setTextFormat(Qt::RichText); … … 1900 1141 connect(mpLatestNewsListWidget, SIGNAL(itemClicked(QListWidgetItem*)), SLOT(openLatestNewsItem(QListWidgetItem*))); 1901 1142 // Latest News Frame layout 1902 QVBoxLayout *latestNewsFrameLayout = new QVBoxLayout; 1903 latestNewsFrameLayout->addWidget(mpLatestNewsLabel); 1904 latestNewsFrameLayout->addWidget(mpLatestNewsListWidget); 1905 latestNewsFrameLayout->addWidget(mpVisitWebsiteLabel, 0 , Qt::AlignRight); 1906 mpLatestNewsFrame->setLayout(latestNewsFrameLayout); 1143 QVBoxLayout *latestNewsFrameVBLayout = new QVBoxLayout; 1144 latestNewsFrameVBLayout->addWidget(mpLatestNewsLabel); 1145 latestNewsFrameVBLayout->addWidget(mpNoLatestNewsLabel); 1146 latestNewsFrameVBLayout->addWidget(mpLatestNewsListWidget); 1147 QHBoxLayout *latestNewsFrameHBLayout = new QHBoxLayout; 1148 latestNewsFrameHBLayout->addWidget(mpReloadLatestNewsButton, 0, Qt::AlignLeft); 1149 latestNewsFrameHBLayout->addWidget(mpVisitWebsiteLabel, 0, Qt::AlignRight); 1150 latestNewsFrameVBLayout->addLayout(latestNewsFrameHBLayout); 1151 mpLatestNewsFrame->setLayout(latestNewsFrameVBLayout); 1907 1152 // create http object for request 1908 1153 mpLatestNewsNetworkAccessManager = new QNetworkAccessManager; … … 1982 1227 void WelcomePageWidget::readLatestNewsXML(QNetworkReply *pNetworkReply) 1983 1228 { 1984 if (pNetworkReply->error() == QNetworkReply::NoError) 1229 if (pNetworkReply->error() == QNetworkReply::HostNotFoundError) 1230 { 1231 mpNoLatestNewsLabel->setVisible(true); 1232 mpNoLatestNewsLabel->setText(tr("Sorry, no internet no news items.")); 1233 } 1234 else if (pNetworkReply->error() == QNetworkReply::NoError) 1985 1235 { 1986 1236 QByteArray response(pNetworkReply->readAll()); … … 1990 1240 while (!xml.atEnd()) 1991 1241 { 1242 mpNoLatestNewsLabel->setVisible(false); 1992 1243 xml.readNext(); 1993 1244 if (xml.tokenType() == QXmlStreamReader::StartElement) … … 2021 1272 break; 2022 1273 } 1274 } 1275 else 1276 { 1277 mpNoLatestNewsLabel->setVisible(true); 1278 mpNoLatestNewsLabel->setText(QString(Helper::error).append(" - ").append(pNetworkReply->errorString())); 2023 1279 } 2024 1280 } … … 2150 1406 else 2151 1407 { 2152 getModelComponents(getLibraryTreeNode()->getNameStructure()); 2153 getModelConnections(); 2154 getModelIconDiagram(); 1408 // getModelComponents(getLibraryTreeNode()->getNameStructure()); 1409 // getModelIconDiagram(); 2155 1410 } 2156 1411 mpIconGraphicsScene->clearSelection(); … … 2221 1476 { 2222 1477 return mpCursorPositionLabel; 2223 }2224 2225 //! Gets the components of the model and place them in the GraphicsView.2226 void ModelWidget::getModelComponents(QString modelName)2227 {2228 MainWindow *pMainWindow = mpModelWidgetContainer->getMainWindow();2229 // get the inherited components of the Model2230 int inheritanceCount = pMainWindow->getOMCProxy()->getInheritanceCount(modelName);2231 2232 for(int i = 1 ; i <= inheritanceCount ; i++)2233 {2234 QString inheritedClass = pMainWindow->getOMCProxy()->getNthInheritedClass(modelName, i);2235 // If the inherited class is one of the builtin type such as Real we can2236 // stop here, because the class can not contain any components, etc.2237 // Look for cycles as well.2238 if (pMainWindow->getOMCProxy()->isBuiltinType(inheritedClass) || inheritedClass.compare(modelName) == 0)2239 {2240 return;2241 }2242 getModelComponents(inheritedClass);2243 }2244 2245 QList<ComponentInfo*> components = pMainWindow->getOMCProxy()->getComponents(modelName);2246 QStringList componentsAnnotationsList = pMainWindow->getOMCProxy()->getComponentAnnotations(modelName);2247 2248 int i = 0;2249 foreach (ComponentInfo *pComponentInfo, components)2250 {2251 if (static_cast<QString>(componentsAnnotationsList.at(i)).toLower().contains("error"))2252 {2253 i++;2254 continue;2255 }2256 if (StringHandler::removeFirstLastCurlBrackets(componentsAnnotationsList.at(i)).length() > 0)2257 {2258 if (pMainWindow->getOMCProxy()->isWhat(StringHandler::CONNECTOR, pComponentInfo->getClassName()))2259 {2260 mpDiagramGraphicsView->addComponentoView(pComponentInfo->getName(), pComponentInfo->getClassName(),2261 componentsAnnotationsList.at(i), QPointF(0.0, 0.0), true, false, true);2262 mpIconGraphicsView->addComponentoView(pComponentInfo->getName(), pComponentInfo->getClassName(),2263 componentsAnnotationsList.at(i), QPointF(0.0, 0.0), true, false);2264 }2265 else2266 {2267 mpDiagramGraphicsView->addComponentoView(pComponentInfo->getName(), pComponentInfo->getClassName(),2268 componentsAnnotationsList.at(i), QPointF(0.0, 0.0), false, false, false);2269 }2270 i++;2271 }2272 }2273 }2274 2275 //! Gets the connections of the model and place them in the GraphicsView.2276 void ModelWidget::getModelConnections()2277 {2278 MainWindow *pMainWindow = mpModelWidgetContainer->getMainWindow();2279 int connectionsCount = pMainWindow->getOMCProxy()->getConnectionCount(getLibraryTreeNode()->getNameStructure());2280 int startindex=-1,endindex=-1;2281 for (int i = 1 ; i <= connectionsCount ; i++)2282 {2283 // get the connection from OMC2284 QString connectionString;2285 QStringList connectionList;2286 connectionString = pMainWindow->getOMCProxy()->getNthConnection(getLibraryTreeNode()->getNameStructure(), i);2287 connectionList = StringHandler::getStrings(StringHandler::removeFirstLastCurlBrackets(connectionString));2288 // if the connectionString only contains two items then continue the loop,2289 // because connection is not valid then2290 if (connectionList.size() < 3)2291 continue;2292 2293 // get start and end components2294 QStringList startComponentList = static_cast<QString>(connectionList.at(0)).split(".");2295 QStringList endComponentList = static_cast<QString>(connectionList.at(1)).split(".");2296 2297 Component *pStartComponent = mpDiagramGraphicsView->getComponentObject(startComponentList.at(0));2298 Component *pEndComponent = mpDiagramGraphicsView->getComponentObject(endComponentList.at(0));2299 2300 // if Start component and end component not found then continue the loop2301 if (!pStartComponent or !pEndComponent)2302 continue;2303 2304 // get start and end ports2305 Component *pStartPort = 0;2306 Component *pEndPort = 0;2307 // if a connector type is connected then we only get one item in startComponentList and endComponentList2308 // check the startcomponentlist2309 if (startComponentList.size() < 2)2310 {2311 pStartPort = pStartComponent;2312 }2313 // look for port from the parent component2314 else2315 {2316 foreach (Component *component, pStartComponent->getComponentsList())2317 {2318 int startbrac = startComponentList.at(1).indexOf("[");2319 if(startbrac == -1)2320 {2321 if (component->getComponentInfo()->getName() == startComponentList.at(1))2322 pStartPort = component;2323 }2324 //if the start port is a connector array2325 else2326 { bool ok;2327 int endbrac = startComponentList.at(1).indexOf("]");2328 QString arrayPort = startComponentList.at(1).left(startbrac);2329 startindex = startComponentList.at(1).mid(startbrac+1,endbrac-startbrac-1).toInt(&ok,10);2330 2331 if (component->getComponentInfo()->getName() == arrayPort)2332 pStartPort = component;2333 }2334 }2335 }2336 // if a connector type is connected then we only get one item in startComponentList and endComponentList2337 // check the startcomponentlist2338 if (endComponentList.size() < 2)2339 {2340 pEndPort = pEndComponent;2341 }2342 // look for port from the parent component2343 else2344 {2345 foreach (Component *component, pEndComponent->getComponentsList())2346 {2347 int startbrac = endComponentList.at(1).indexOf("[");2348 if(startbrac == -1)2349 {2350 if (component->getComponentInfo()->getName() == endComponentList.at(1))2351 pEndPort = component;2352 }2353 //if the end port is a connector array2354 else2355 { bool ok;2356 int endbrac = endComponentList.at(1).indexOf("]");2357 QString arrayPort = endComponentList.at(1).left(startbrac);2358 endindex = endComponentList.at(1).mid(startbrac+1,endbrac-startbrac-1).toInt(&ok,10);2359 if (component->getComponentInfo()->getName() == arrayPort)2360 pEndPort = component;2361 }2362 }2363 }2364 2365 // if Start port and end port not found then continue the loop2366 if (!pStartPort or !pEndPort)2367 continue;2368 2369 // get the connector annotations from OMC2370 QString connectionAnnotationString;2371 QStringList connectionAnnotationList, shapesList;2372 connectionAnnotationString = pMainWindow->getOMCProxy()->getNthConnectionAnnotation(getLibraryTreeNode()->getNameStructure(), i);2373 shapesList = StringHandler::getStrings(StringHandler::removeFirstLastCurlBrackets(connectionAnnotationString), '(', ')');2374 // Now parse the shapes available in list2375 foreach (QString shape, shapesList)2376 {2377 shape = StringHandler::removeFirstLastCurlBrackets(shape);2378 if (shape.startsWith("Line"))2379 {2380 shape = shape.mid(QString("Line").length());2381 connectionAnnotationString = StringHandler::removeFirstLastBrackets(shape);2382 }2383 }2384 connectionAnnotationList = StringHandler::getStrings(connectionAnnotationString);2385 // if the connectionAnnotationString is empty then continue the loop,2386 // because connection is not valid then2387 if (connectionAnnotationList.size() < 8)2388 continue;2389 2390 // create a QVector<QPointF> of annotation string to pass to connector2391 QStringList pointsList;2392 QVector<QPointF> points;2393 pointsList = StringHandler::getStrings(StringHandler::removeFirstLastCurlBrackets(connectionAnnotationList.at(3)));2394 2395 foreach (QString point, pointsList)2396 {2397 QStringList linePoints = StringHandler::getStrings(StringHandler::removeFirstLastCurlBrackets(point));2398 if (linePoints.size() < 2)2399 continue;2400 2401 qreal x = static_cast<QString>(linePoints.at(0)).toFloat();2402 qreal y = static_cast<QString>(linePoints.at(1)).toFloat();2403 QPointF p (x, y);2404 points.append(p);2405 }2406 // create a connector now2407 Connector *pConnector = new Connector(pStartPort, pEndPort, mpDiagramGraphicsView, points);2408 //checking for the created connector to be a connector array2409 if(startindex>=0)2410 pConnector->setStartConnectorisArray(true);2411 if(endindex>=0)2412 pConnector->setEndConnectorisArray(true);2413 //storing array indices for the connector array2414 pConnector->mpConnectorArrayMenu->setStartConnectorIndex(QString::number(startindex));2415 pConnector->mpConnectorArrayMenu->setEndConnectorIndex(QString::number(endindex));2416 mpDiagramGraphicsView->mConnectorsVector.append(pConnector);2417 mpDiagramGraphicsView->scene()->addItem(pConnector);2418 }2419 }2420 2421 //! Gets the shapes contained in the annotation string.2422 void ModelWidget::getModelShapes(QString className, int viewType)2423 {2424 MainWindow *pMainWindow = mpModelWidgetContainer->getMainWindow();2425 // get the inherited components of the Model2426 int inheritanceCount = pMainWindow->getOMCProxy()->getInheritanceCount(className);2427 for(int i = 1 ; i <= inheritanceCount ; i++)2428 {2429 QString inheritedClass = pMainWindow->getOMCProxy()->getNthInheritedClass(className, i);2430 // If the inherited class is one of the builtin type such as Real we can2431 // stop here, because the class can not contain any components, etc.2432 // Look for cycles as well.2433 if (pMainWindow->getOMCProxy()->isBuiltinType(inheritedClass) || inheritedClass.compare(className) == 0)2434 {2435 return;2436 }2437 getModelShapes(inheritedClass, viewType);2438 }2439 // get the annotation2440 QString annotationString;2441 if (viewType == StringHandler::ICON)2442 annotationString = pMainWindow->getOMCProxy()->getIconAnnotation(className);2443 else if (viewType == StringHandler::DIAGRAM)2444 annotationString = pMainWindow->getOMCProxy()->getDiagramAnnotation(className);2445 // parse annotation string2446 annotationString = StringHandler::removeFirstLastCurlBrackets(annotationString);2447 if (annotationString.isEmpty())2448 {2449 return;2450 }2451 QStringList list = StringHandler::getStrings(annotationString);2452 if (list.size() < 8)2453 return;2454 // read the extent points2455 qreal left = list.at(0).toFloat();2456 qreal bottom = list.at(1).toFloat();2457 qreal right = list.at(2).toFloat();2458 qreal top = list.at(3).toFloat();2459 QList<QPointF> extent;2460 extent << QPointF(left, bottom) << QPointF(right, top);2461 // read the preserveAspectRatio2462 bool preserveAspectRatio = list.at(4).contains("true");2463 // read the initialScale2464 qreal initialScale = list.at(5).toFloat();2465 // read the grid2466 qreal horizontal = list.at(6).toFloat();2467 qreal vertical = list.at(7).toFloat();2468 QPointF grid(horizontal, vertical);2469 // set the coOrdinate system for the layer2470 if (viewType == StringHandler::ICON)2471 {2472 mpIconGraphicsView->getCoOrdinateSystem()->setExtent(extent);2473 mpIconGraphicsView->getCoOrdinateSystem()->setPreserveAspectRatio(preserveAspectRatio);2474 mpIconGraphicsView->getCoOrdinateSystem()->setInitialScale(initialScale);2475 mpIconGraphicsView->getCoOrdinateSystem()->setGrid(grid);2476 // update the graphics view scene rect2477 mpIconGraphicsView->setSceneRect(left, bottom, fabs(left - right), fabs(bottom - top));2478 mpIconGraphicsView->updateGeometry();2479 }2480 else2481 {2482 mpDiagramGraphicsView->getCoOrdinateSystem()->setExtent(extent);2483 mpDiagramGraphicsView->getCoOrdinateSystem()->setPreserveAspectRatio(preserveAspectRatio);2484 mpDiagramGraphicsView->getCoOrdinateSystem()->setInitialScale(initialScale);2485 mpDiagramGraphicsView->getCoOrdinateSystem()->setGrid(grid);2486 // update the graphics view scene rect2487 mpDiagramGraphicsView->setSceneRect(left, bottom, fabs(left - right), fabs(bottom - top));2488 mpDiagramGraphicsView->updateGeometry();2489 }2490 if (list.size() < 9)2491 return;2492 // read the shapes2493 QStringList shapesList = StringHandler::getStrings(StringHandler::removeFirstLastCurlBrackets(list.at(8)), '(', ')');2494 // Now parse the shapes available in list2495 foreach (QString shape, shapesList)2496 {2497 shape = StringHandler::removeFirstLastCurlBrackets(shape);2498 if (shape.startsWith("Line"))2499 {2500 shape = shape.mid(QString("Line").length());2501 shape = StringHandler::removeFirstLastBrackets(shape);2502 LineAnnotation *lineAnnotation;2503 // add the shapeannotation item to shapes list2504 if (viewType == StringHandler::ICON)2505 {2506 lineAnnotation = new LineAnnotation(shape, mpIconGraphicsView);2507 lineAnnotation->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);2508 mpIconGraphicsView->addShapeObject(lineAnnotation);2509 mpIconGraphicsView->scene()->addItem(lineAnnotation);2510 }2511 else if (viewType == StringHandler::DIAGRAM)2512 {2513 lineAnnotation = new LineAnnotation(shape, mpDiagramGraphicsView);2514 lineAnnotation->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);2515 mpDiagramGraphicsView->addShapeObject(lineAnnotation);2516 mpDiagramGraphicsView->scene()->addItem(lineAnnotation);2517 }2518 /*2519 before drawing the rectangle corner items add one point to line since drawrectanglecorneritems2520 deletes the one point. Why? because we end the line shape with double click which adds an extra2521 point to it. so we need to delete that point.2522 */2523 lineAnnotation->addPoint(QPoint(0, 0));2524 lineAnnotation->drawRectangleCornerItems();2525 lineAnnotation->setSelectionBoxPassive();2526 }2527 if (shape.startsWith("Polygon"))2528 {2529 shape = shape.mid(QString("Polygon").length());2530 shape = StringHandler::removeFirstLastBrackets(shape);2531 PolygonAnnotation *polygonAnnotation;2532 // add the shapeannotation item to shapes list2533 if (viewType == StringHandler::ICON)2534 {2535 polygonAnnotation = new PolygonAnnotation(shape, mpIconGraphicsView);2536 polygonAnnotation->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);2537 mpIconGraphicsView->addShapeObject(polygonAnnotation);2538 mpIconGraphicsView->scene()->addItem(polygonAnnotation);2539 }2540 else if (viewType == StringHandler::DIAGRAM)2541 {2542 polygonAnnotation = new PolygonAnnotation(shape, mpDiagramGraphicsView);2543 polygonAnnotation->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);2544 mpDiagramGraphicsView->addShapeObject(polygonAnnotation);2545 mpDiagramGraphicsView->scene()->addItem(polygonAnnotation);2546 }2547 /*2548 before drawing the rectangle corner items add one point to polygon since drawrectanglecorneritems2549 deletes the one point. Why? because we end the polygon shape with double click which adds an extra2550 point to it. so we need to delete that point.2551 */2552 polygonAnnotation->addPoint(QPoint(0, 0));2553 polygonAnnotation->drawRectangleCornerItems();2554 polygonAnnotation->setSelectionBoxPassive();2555 }2556 if (shape.startsWith("Rectangle"))2557 {2558 shape = shape.mid(QString("Rectangle").length());2559 shape = StringHandler::removeFirstLastBrackets(shape);2560 RectangleAnnotation *rectangleAnnotation;2561 // add the shapeannotation item to shapes list2562 if (viewType == StringHandler::ICON)2563 {2564 rectangleAnnotation = new RectangleAnnotation(shape, mpIconGraphicsView);2565 rectangleAnnotation->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);2566 mpIconGraphicsView->addShapeObject(rectangleAnnotation);2567 mpIconGraphicsView->scene()->addItem(rectangleAnnotation);2568 }2569 else if (viewType == StringHandler::DIAGRAM)2570 {2571 rectangleAnnotation = new RectangleAnnotation(shape, mpDiagramGraphicsView);2572 rectangleAnnotation->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);2573 mpDiagramGraphicsView->addShapeObject(rectangleAnnotation);2574 mpDiagramGraphicsView->scene()->addItem(rectangleAnnotation);2575 }2576 rectangleAnnotation->drawRectangleCornerItems();2577 rectangleAnnotation->setSelectionBoxPassive();2578 }2579 if (shape.startsWith("Ellipse"))2580 {2581 shape = shape.mid(QString("Ellipse").length());2582 shape = StringHandler::removeFirstLastBrackets(shape);2583 EllipseAnnotation *ellipseAnnotation;2584 // add the shapeannotation item to shapes list2585 if (viewType == StringHandler::ICON)2586 {2587 ellipseAnnotation = new EllipseAnnotation(shape, mpIconGraphicsView);2588 ellipseAnnotation->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);2589 mpIconGraphicsView->addShapeObject(ellipseAnnotation);2590 mpIconGraphicsView->scene()->addItem(ellipseAnnotation);2591 }2592 else if (viewType == StringHandler::DIAGRAM)2593 {2594 ellipseAnnotation = new EllipseAnnotation(shape, mpDiagramGraphicsView);2595 ellipseAnnotation->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);2596 mpDiagramGraphicsView->addShapeObject(ellipseAnnotation);2597 mpDiagramGraphicsView->scene()->addItem(ellipseAnnotation);2598 }2599 ellipseAnnotation->drawRectangleCornerItems();2600 ellipseAnnotation->setSelectionBoxPassive();2601 }2602 if (shape.startsWith("Text"))2603 {2604 shape = shape.mid(QString("Text").length());2605 shape = StringHandler::removeFirstLastBrackets(shape);2606 TextAnnotation *textAnnotation;2607 // add the shapeannotation item to shapes list2608 if (viewType == StringHandler::ICON)2609 {2610 textAnnotation = new TextAnnotation(shape, mpIconGraphicsView);2611 textAnnotation->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);2612 mpIconGraphicsView->addShapeObject(textAnnotation);2613 mpIconGraphicsView->scene()->addItem(textAnnotation);2614 }2615 else if (viewType == StringHandler::DIAGRAM)2616 {2617 textAnnotation = new TextAnnotation(shape, mpDiagramGraphicsView);2618 textAnnotation->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);2619 mpDiagramGraphicsView->addShapeObject(textAnnotation);2620 mpDiagramGraphicsView->scene()->addItem(textAnnotation);2621 }2622 textAnnotation->drawRectangleCornerItems();2623 textAnnotation->setSelectionBoxPassive();2624 }2625 if (shape.startsWith("Bitmap"))2626 {2627 shape = shape.mid(QString("Bitmap").length());2628 shape = StringHandler::removeFirstLastBrackets(shape);2629 BitmapAnnotation *bitmapAnnotation;2630 // add the shapeannotation item to shapes list2631 if (viewType == StringHandler::ICON)2632 {2633 bitmapAnnotation = new BitmapAnnotation(shape, mpIconGraphicsView);2634 bitmapAnnotation->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);2635 mpIconGraphicsView->addShapeObject(bitmapAnnotation);2636 mpIconGraphicsView->scene()->addItem(bitmapAnnotation);2637 }2638 else if (viewType == StringHandler::DIAGRAM)2639 {2640 bitmapAnnotation = new BitmapAnnotation(shape, mpDiagramGraphicsView);2641 bitmapAnnotation->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);2642 mpDiagramGraphicsView->addShapeObject(bitmapAnnotation);2643 mpDiagramGraphicsView->scene()->addItem(bitmapAnnotation);2644 }2645 bitmapAnnotation->drawRectangleCornerItems();2646 bitmapAnnotation->setSelectionBoxPassive();2647 }2648 }2649 }2650 2651 //! Gets the Icon and Diagram Annotation of the model and place them in the GraphicsView (Icon View).2652 void ModelWidget::getModelIconDiagram()2653 {2654 getModelShapes(getLibraryTreeNode()->getNameStructure(), StringHandler::ICON);2655 getModelShapes(getLibraryTreeNode()->getNameStructure(), StringHandler::DIAGRAM);2656 1478 } 2657 1479
Note: See TracChangeset
for help on using the changeset viewer.