-
Notifications
You must be signed in to change notification settings - Fork 296
/
ModelWidgetContainer.h
703 lines (686 loc) · 31.2 KB
/
ModelWidgetContainer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
* THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
* RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
* ACCORDING TO RECIPIENTS CHOICE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from OSMC, either from the above address,
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
* http://www.openmodelica.org, and in the OpenModelica distribution.
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/
/*
* @author Adeel Asghar <adeel.asghar@liu.se>
*/
#ifndef MODELWIDGETCONTAINER_H
#define MODELWIDGETCONTAINER_H
#include "CoOrdinateSystem.h"
#include "Element/Element.h"
#include "Util/StringHandler.h"
#include "Util/Helper.h"
#include "Editors/BaseEditor.h"
#include "Editors/ModelicaEditor.h"
#include "Editors/CompositeModelEditor.h"
#include "Editors/OMSimulatorEditor.h"
#include "Editors/CEditor.h"
#include "Editors/TextEditor.h"
#include "Editors/MetaModelicaEditor.h"
#include "LibraryTreeWidget.h"
#include "OMSimulator.h"
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QStatusBar>
#include <QListWidget>
#include <QMdiArea>
#include <QtWebKit>
#include <QtXmlPatterns>
#include <QSplitter>
#include <QUndoStack>
#include <QUndoView>
class ModelWidget;
class ElementInfo;
class LineAnnotation;
class PolygonAnnotation;
class RectangleAnnotation;
class EllipseAnnotation;
class TextAnnotation;
class BitmapAnnotation;
class NetworkAccessManager;
class GraphicsScene : public QGraphicsScene
{
Q_OBJECT
public:
GraphicsScene(StringHandler::ViewType viewType, ModelWidget *pModelWidget);
ModelWidget *mpModelWidget;
StringHandler::ViewType mViewType;
};
class LibraryTreeItem;
class GraphicsView : public QGraphicsView
{
Q_OBJECT
private:
StringHandler::ViewType mViewType;
ModelWidget *mpModelWidget;
CoOrdinateSystem mCoOrdinateSystem;
public:
CoOrdinateSystem mMergedCoOrdinateSystem;
CoOrdinateSystem getCoOrdinateSystem() const {return mCoOrdinateSystem;}
void setCoOrdinateSystem(const CoOrdinateSystem coOrdinateSystem) {mCoOrdinateSystem = coOrdinateSystem;}
private:
bool mVisualizationView;
bool mIsCustomScale;
bool mAddClassAnnotationNeeded;
bool mIsCreatingConnection;
bool mIsCreatingTransition;
bool mIsCreatingLineShape;
bool mIsCreatingPolygonShape;
bool mIsCreatingRectangleShape;
bool mIsCreatingEllipseShape;
bool mIsCreatingTextShape;
bool mIsCreatingBitmapShape;
bool mIsPanning;
QPoint mLastMouseEventPos;
Element *mpClickedComponent;
Element *mpClickedState;
bool mIsMovingComponentsAndShapes;
bool mRenderingLibraryPixmap;
QList<Element*> mElementsList;
// A list of components that are not deleted but are removed from scene.
QList<Element*> mOutOfSceneElementsList;
QList<LineAnnotation*> mConnectionsList;
QList<LineAnnotation*> mOutOfSceneConnectionsList;
QList<LineAnnotation*> mTransitionsList;
QList<LineAnnotation*> mOutOfSceneTransitionsList;
QList<LineAnnotation*> mInitialStatesList;
QList<LineAnnotation*> mOutOfSceneInitialStatesList;
QList<ShapeAnnotation*> mShapesList;
QList<ShapeAnnotation*> mOutOfSceneShapesList;
QList<Element*> mInheritedElementsList;
QList<LineAnnotation*> mInheritedConnectionsList;
QList<ShapeAnnotation*> mInheritedShapesList;
LineAnnotation *mpConnectionLineAnnotation;
LineAnnotation *mpTransitionLineAnnotation;
LineAnnotation *mpLineShapeAnnotation;
PolygonAnnotation *mpPolygonShapeAnnotation;
RectangleAnnotation *mpRectangleShapeAnnotation;
EllipseAnnotation *mpEllipseShapeAnnotation;
TextAnnotation *mpTextShapeAnnotation;
BitmapAnnotation *mpBitmapShapeAnnotation;
QAction *mpPropertiesAction;
QAction *mpRenameAction;
QAction *mpSimulationParamsAction;
QAction *mpManhattanizeAction;
QAction *mpDeleteAction;
QAction *mpBringToFrontAction;
QAction *mpBringForwardAction;
QAction *mpSendToBackAction;
QAction *mpSendBackwardAction;
QAction *mpCutAction;
QAction *mpCopyAction;
QAction *mpPasteAction;
QAction *mpDuplicateAction;
QAction *mpRotateClockwiseAction;
QAction *mpRotateAntiClockwiseAction;
QAction *mpFlipHorizontalAction;
QAction *mpFlipVerticalAction;
QAction *mpSetInitialStateAction;
QAction *mpCancelTransitionAction;
// scene->items().contains(...) involves sorting on each items() call, avoid it
QSet<QGraphicsItem*> mAllItems;
public:
GraphicsView(StringHandler::ViewType viewType, ModelWidget *pModelWidget, bool visualizationView = false);
bool mSkipBackground; /* Do not draw the background rectangle */
StringHandler::ViewType getViewType() {return mViewType;}
ModelWidget* getModelWidget() {return mpModelWidget;}
bool isVisualizationView() {return mVisualizationView;}
void setExtentRectangle(const QRectF rectangle);
void setIsCustomScale(bool enable) {mIsCustomScale = enable;}
bool isCustomScale() {return mIsCustomScale;}
void setAddClassAnnotationNeeded(bool needed) {mAddClassAnnotationNeeded = needed;}
bool isAddClassAnnotationNeeded() {return mAddClassAnnotationNeeded;}
void setIsCreatingConnection(const bool enable);
bool isCreatingConnection() {return mIsCreatingConnection;}
void setIsCreatingTransition(const bool enable);
bool isCreatingTransition() {return mIsCreatingTransition;}
void setIsCreatingLineShape(const bool enable);
bool isCreatingLineShape() {return mIsCreatingLineShape;}
void setIsCreatingPolygonShape(const bool enable);
bool isCreatingPolygonShape() {return mIsCreatingPolygonShape;}
void setIsCreatingRectangleShape(const bool enable);
bool isCreatingRectangleShape() {return mIsCreatingRectangleShape;}
void setIsCreatingEllipseShape(const bool enable);
bool isCreatingEllipseShape() {return mIsCreatingEllipseShape;}
void setIsCreatingTextShape(const bool enable);
bool isCreatingTextShape() {return mIsCreatingTextShape;}
void setIsCreatingBitmapShape(const bool enable);
bool isCreatingBitmapShape() {return mIsCreatingBitmapShape;}
void setIsCreatingPrologue(const bool enable);
void setIsPanning(bool enable);
bool isPanning() {return mIsPanning;}
void setDragModeInternal(bool enable, bool updateCursor = false);
void setItemsFlags(bool enable);
void updateUndoRedoActions(bool enable);
void setIsMovingComponentsAndShapes(bool enable) {mIsMovingComponentsAndShapes = enable;}
bool isMovingComponentsAndShapes() {return mIsMovingComponentsAndShapes;}
void setRenderingLibraryPixmap(bool renderingLibraryPixmap) {mRenderingLibraryPixmap = renderingLibraryPixmap;}
bool isRenderingLibraryPixmap() {return mRenderingLibraryPixmap;}
QList<ShapeAnnotation*> getShapesList() {return mShapesList;}
QList<ShapeAnnotation*> getInheritedShapesList() {return mInheritedShapesList;}
QAction* getManhattanizeAction() {return mpManhattanizeAction;}
QAction* getDeleteAction() {return mpDeleteAction;}
QAction* getCutAction() {return mpCutAction;}
QAction* getCopyAction() {return mpCopyAction;}
QAction* getPasteAction() {return mpPasteAction;}
QAction* getDuplicateAction() {return mpDuplicateAction;}
QAction* getBringToFrontAction() {return mpBringToFrontAction;}
QAction* getBringForwardAction() {return mpBringForwardAction;}
QAction* getSendToBackAction() {return mpSendToBackAction;}
QAction* getSendBackwardAction() {return mpSendBackwardAction;}
QAction* getRotateClockwiseAction() {return mpRotateClockwiseAction;}
QAction* getRotateAntiClockwiseAction() {return mpRotateAntiClockwiseAction;}
QAction* getFlipHorizontalAction() {return mpFlipHorizontalAction;}
QAction* getFlipVerticalAction() {return mpFlipVerticalAction;}
bool addComponent(QString className, QPointF position);
void addComponentToView(QString name, LibraryTreeItem *pLibraryTreeItem, QString annotation, QPointF position,
ElementInfo *pComponentInfo, bool addObject, bool openingClass, bool emitComponentAdded);
void addElementToList(Element *pElement) {mElementsList.append(pElement);}
void addElementToOutOfSceneList(Element *pElement) {mOutOfSceneElementsList.append(pElement);}
void addInheritedElementToList(Element *pElement) {mInheritedElementsList.append(pElement);}
void addElementToClass(Element *pElement);
void deleteElement(Element *pElement);
void deleteElementFromClass(Element *pElement);
void deleteElementFromList(Element *pElement) {mElementsList.removeOne(pElement);}
void deleteElementFromOutOfSceneList(Element *pElement) {mOutOfSceneElementsList.removeOne(pElement);}
void deleteInheritedElementFromList(Element *pElement) {mInheritedElementsList.removeOne(pElement);}
Element* getElementObject(QString elementName);
QString getUniqueElementName(QString elementName, int number = 0);
bool checkElementName(QString elementName);
QList<Element*> getElementsList() {return mElementsList;}
QList<Element*> getInheritedElementsList() {return mInheritedElementsList;}
QList<LineAnnotation*> getConnectionsList() {return mConnectionsList;}
QList<LineAnnotation*> getInheritedConnectionsList() {return mInheritedConnectionsList;}
void addConnectionToView(LineAnnotation *pConnectionLineAnnotation);
bool addConnectionToClass(LineAnnotation *pConnectionLineAnnotation, bool deleteUndo = false);
void deleteConnectionFromClass(LineAnnotation *pConnectionLineAnnotation);
void updateConnectionInClass(LineAnnotation *pConnectionLineAnnotation);
void addConnectionToList(LineAnnotation *pConnectionLineAnnotation) {mConnectionsList.append(pConnectionLineAnnotation);}
void addConnectionToOutOfSceneList(LineAnnotation *pConnectionLineAnnotation) {mOutOfSceneConnectionsList.append(pConnectionLineAnnotation);}
void addInheritedConnectionToList(LineAnnotation *pConnectionLineAnnotation) {mInheritedConnectionsList.append(pConnectionLineAnnotation);}
void deleteConnectionFromList(LineAnnotation *pConnectionLineAnnotation) {mConnectionsList.removeOne(pConnectionLineAnnotation);}
void deleteConnectionFromOutOfSceneList(LineAnnotation *pConnectionLineAnnotation) {mOutOfSceneConnectionsList.removeOne(pConnectionLineAnnotation);}
void removeConnectionFromView(LineAnnotation *pConnectionLineAnnotation);
void removeConnectionsFromView();
void deleteInheritedConnectionFromList(LineAnnotation *pConnectionLineAnnotation) {mInheritedConnectionsList.removeOne(pConnectionLineAnnotation);}
int numberOfComponentConnections(Element *pComponent, LineAnnotation *pExcludeConnectionLineAnnotation = 0);
QList<LineAnnotation*> getTransitionsList() {return mTransitionsList;}
void addTransitionToClass(LineAnnotation *pTransitionLineAnnotation);
void deleteTransitionFromClass(LineAnnotation *pTransitionLineAnnotation);
void addTransitionToList(LineAnnotation *pTransitionLineAnnotation) {mTransitionsList.append(pTransitionLineAnnotation);}
void addTransitionToOutOfSceneList(LineAnnotation *pTransitionLineAnnotation) {mOutOfSceneTransitionsList.append(pTransitionLineAnnotation);}
void deleteTransitionFromList(LineAnnotation *pTransitionLineAnnotation) {mTransitionsList.removeOne(pTransitionLineAnnotation);}
void deleteTransitionFromOutOfSceneList(LineAnnotation *pTransitionLineAnnotation) {mOutOfSceneTransitionsList.removeOne(pTransitionLineAnnotation);}
void removeTransitionsFromView();
QList<LineAnnotation*> getInitialStatesList() {return mInitialStatesList;}
void addInitialStateToClass(LineAnnotation *pInitialStateLineAnnotation);
void deleteInitialStateFromClass(LineAnnotation *pInitialStateLineAnnotation);
void addInitialStateToList(LineAnnotation *pInitialStateLineAnnotation) {mInitialStatesList.append(pInitialStateLineAnnotation);}
void addInitialStateToOutOfSceneList(LineAnnotation *pInitialStateLineAnnotation) {mOutOfSceneInitialStatesList.append(pInitialStateLineAnnotation);}
void deleteInitialStateFromList(LineAnnotation *pInitialStateLineAnnotation) {mInitialStatesList.removeOne(pInitialStateLineAnnotation);}
void deleteInitialStateFromOutOfSceneList(LineAnnotation *pInitialStateLineAnnotation) {mOutOfSceneInitialStatesList.removeOne(pInitialStateLineAnnotation);}
void removeInitialStatesFromView();
void addShapeToList(ShapeAnnotation *pShape, int index = -1);
void addShapeToOutOfSceneList(ShapeAnnotation *pShape) {mOutOfSceneShapesList.append(pShape);}
void addInheritedShapeToList(ShapeAnnotation *pShape) {mInheritedShapesList.append(pShape);}
void deleteShape(ShapeAnnotation *pShapeAnnotation);
int deleteShapeFromList(ShapeAnnotation *pShape);
void deleteShapeFromOutOfSceneList(ShapeAnnotation *pShape) {mOutOfSceneShapesList.removeOne(pShape);}
void deleteInheritedShapeFromList(ShapeAnnotation *pShape) {mInheritedShapesList.removeOne(pShape);}
void reOrderShapes();
void bringToFront(ShapeAnnotation *pShape);
void bringForward(ShapeAnnotation *pShape);
void sendToBack(ShapeAnnotation *pShape);
void sendBackward(ShapeAnnotation *pShape);
void clearGraphicsView();
void removeClassComponents();
void removeOutOfSceneClassComponents();
void removeInheritedClassShapes();
void removeInheritedClassElements();
void removeInheritedClassConnections();
void removeAllShapes() {mShapesList.clear();}
void removeOutOfSceneShapes();
void removeAllConnections() {mConnectionsList.clear();}
void removeOutOfSceneConnections();
void removeAllTransitions() {mTransitionsList.clear();}
void removeOutOfSceneTransitions();
void removeAllInitialStates() {mInitialStatesList.clear();}
void removeOutOfSceneInitialStates();
void createLineShape(QPointF point);
void createPolygonShape(QPointF point);
void createRectangleShape(QPointF point);
void createEllipseShape(QPointF point);
void createTextShape(QPointF point);
void createBitmapShape(QPointF point);
QRectF itemsBoundingRect();
QPointF snapPointToGrid(QPointF point);
QPointF movePointByGrid(QPointF point, QPointF origin = QPointF(0, 0), bool useShiftModifier = false);
QPointF roundPoint(QPointF point);
bool hasAnnotation();
void addItem(QGraphicsItem *pGraphicsItem);
void removeItem(QGraphicsItem *pGraphicsItem);
void fitInViewInternal();
private:
void createActions();
bool isClassDroppedOnItself(LibraryTreeItem *pLibraryTreeItem);
bool isAnyItemSelectedAndEditable(int key);
bool isCreatingShape();
Element* getElementFromQGraphicsItem(QGraphicsItem *pGraphicsItem);
Element* elementAtPosition(QPoint position);
Element* connectorComponentAtPosition(QPoint position);
Element* stateComponentAtPosition(QPoint position);
static bool updateComponentConnectorSizingParameter(GraphicsView *pGraphicsView, QString className, Element *pComponent);
bool handleDoubleClickOnComponent(QMouseEvent *event);
void uncheckAllShapeDrawingActions();
void setOriginAdjustAndInitialize(ShapeAnnotation* shapeAnnotation);
void setOriginAdjustAndInitialize(PolygonAnnotation* shapeAnnotation);
void adjustInitializeDraw(ShapeAnnotation* shapeAnnotation);
void finishDrawingGenericShape();
void finishDrawingLineShape(bool removeLastAddedPoint = false);
void finishDrawingPolygonShape(bool removeLastAddedPoint = false);
void finishDrawingRectangleShape();
void finishDrawingEllipseShape();
void finishDrawingTextShape();
void finishDrawingBitmapShape();
void checkEmitUpdateSelect(const bool showPropertiesAndSelect, ShapeAnnotation* shapeAnnotation);
void copyItems(bool cut);
void modelicaGraphicsViewContextMenu(QMenu *pMenu);
void modelicaOneShapeContextMenu(ShapeAnnotation *pShapeAnnotation, QMenu *pMenu);
void modelicaOneComponentContextMenu(Element *pComponent, QMenu *pMenu);
void modelicaMultipleItemsContextMenu(QMenu *pMenu);
void compositeModelGraphicsViewContextMenu(QMenu *pMenu);
void compositeModelOneShapeContextMenu(ShapeAnnotation *pShapeAnnotation, QMenu *pMenu);
void compositeModelOneComponentContextMenu(Element *pComponent, QMenu *pMenu);
void compositeModelMultipleItemsContextMenu(QMenu *pMenu);
void omsGraphicsViewContextMenu(QMenu *pMenu);
void omsOneShapeContextMenu(ShapeAnnotation *pShapeAnnotation, QMenu *pMenu);
void omsOneComponentContextMenu(Element *pComponent, QMenu *pMenu);
void omsMultipleItemsContextMenu(QMenu *pMenu);
signals:
void manhattanize();
void deleteSignal();
void mouseDuplicate();
void mouseRotateClockwise();
void mouseRotateAntiClockwise();
void mouseFlipHorizontal();
void mouseFlipVertical();
void keyPressRotateClockwise();
void keyPressRotateAntiClockwise();
void keyPressFlipHorizontal();
void keyPressFlipVertical();
void keyPressUp();
void keyPressShiftUp();
void keyPressCtrlUp();
void keyPressDown();
void keyPressShiftDown();
void keyPressCtrlDown();
void keyPressLeft();
void keyPressShiftLeft();
void keyPressCtrlLeft();
void keyPressRight();
void keyPressShiftRight();
void keyPressCtrlRight();
void keyPressDuplicate();
public slots:
void addConnection(Element *pComponent);
void removeCurrentConnection();
void deleteConnection(LineAnnotation *pConnectionLineAnnotation);
void addTransition(Element *pComponent);
void removeCurrentTransition();
void deleteTransition(LineAnnotation *pTransitionLineAnnotation);
void deleteInitialState(LineAnnotation *pInitialLineAnnotation);
void resetZoom();
void zoomIn();
void zoomOut();
void selectAll();
void cutItems();
void copyItems();
void pasteItems();
void clearSelection(QGraphicsItem *pSelectGraphicsItem = 0);
void addClassAnnotation(bool alwaysAdd = true);
void showGraphicsViewProperties();
void showRenameDialog();
void showSimulationParamsDialog();
void manhattanizeItems();
void deleteItems();
void duplicateItems();
void rotateClockwise();
void rotateAntiClockwise();
void flipHorizontal();
void flipVertical();
void setInitialState();
void cancelTransition();
protected:
virtual void dragMoveEvent(QDragMoveEvent *event) override;
virtual void dropEvent(QDropEvent *event) override;
virtual void drawBackground(QPainter *painter, const QRectF &rect) override;
virtual void mousePressEvent(QMouseEvent *event) override;
virtual void mouseMoveEvent(QMouseEvent *event) override;
virtual void mouseReleaseEvent(QMouseEvent *event) override;
virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
virtual void focusOutEvent(QFocusEvent *event) override;
virtual void keyPressEvent(QKeyEvent *event) override;
virtual void keyReleaseEvent(QKeyEvent *event) override;
virtual void contextMenuEvent(QContextMenuEvent *event) override;
virtual void resizeEvent(QResizeEvent *event) override;
virtual void wheelEvent(QWheelEvent *event) override;
virtual void leaveEvent(QEvent *event) override;
};
class WelcomePageWidget : public QWidget
{
Q_OBJECT
public:
WelcomePageWidget(QWidget *pParent = 0);
void addRecentFilesListItems();
QFrame* getLatestNewsFrame();
QSplitter* getSplitter();
private:
QFrame *mpMainFrame;
QFrame *mpTopFrame;
Label *mpPixmapLabel;
Label *mpHeadingLabel;
QFrame *mpRecentFilesFrame;
Label *mpRecentFilesLabel;
Label *mpNoRecentFileLabel;
QListWidget *mpRecentItemsList;
QPushButton *mpClearRecentFilesListButton;
QFrame *mpLatestNewsFrame;
Label *mpLatestNewsLabel;
Label *mpNoLatestNewsLabel;
QListWidget *mpLatestNewsListWidget;
QPushButton *mpReloadLatestNewsButton;
Label *mpVisitWebsiteLabel;
NetworkAccessManager *mpLatestNewsNetworkAccessManager;
QSplitter *mpSplitter;
QFrame *mpBottomFrame;
QPushButton *mpCreateModelButton;
QPushButton *mpOpenModelButton;
public slots:
void addLatestNewsListItems();
private slots:
void readLatestNewsXML(QNetworkReply *pNetworkReply);
void openRecentFileItem(QListWidgetItem *pItem);
void openLatestNewsItem(QListWidgetItem *pItem);
};
class UndoCommand;
class UndoStack : public QUndoStack
{
Q_OBJECT
public:
UndoStack(QObject *parent = 0);
void push(UndoCommand *cmd);
bool isEnabled() {return mEnabled;}
void setEnabled(bool enable) {mEnabled = enable;}
private:
bool mEnabled;
};
class IconDiagramMap
{
public:
IconDiagramMap()
{
mExtent.clear();
mExtent << QPointF(0, 0) << QPointF(0, 0);
mPrimitivesVisible = true;
}
QList<QPointF> mExtent;
bool mPrimitivesVisible;
};
class MimeData : public QMimeData
{
Q_OBJECT
public:
MimeData() : QMimeData()
{
mComponents.clear();
mConnections.clear();
mShapes.clear();
}
void addComponent(Element *pComponent) {mComponents.append(pComponent);}
QList<Element*> getComponents() const {return mComponents;}
void addConnection(LineAnnotation *pConnectionLineAnnotation) {mConnections.append(pConnectionLineAnnotation);}
QList<LineAnnotation*> getConnections() const {return mConnections;}
void addShape(ShapeAnnotation *pShapeAnnotation) {mShapes.append(pShapeAnnotation);}
QList<ShapeAnnotation*> getShapes() const {return mShapes;}
private:
QList<Element*> mComponents;
QList<LineAnnotation*> mConnections;
QList<ShapeAnnotation*> mShapes;
// QMimeData interface
public:
virtual QStringList formats() const override
{
return QStringList() << "text/plain" << Helper::cutCopyPasteFormat;
}
};
class ModelWidgetContainer;
class ModelicaHighlighter;
class CompositeModelHighlighter;
class Label;
class ModelWidget : public QWidget
{
Q_OBJECT
public:
ModelWidget(LibraryTreeItem* pLibraryTreeItem, ModelWidgetContainer *pModelWidgetContainer);
ModelWidgetContainer* getModelWidgetContainer() {return mpModelWidgetContainer;}
void setLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem) {mpLibraryTreeItem = pLibraryTreeItem;}
LibraryTreeItem* getLibraryTreeItem() {return mpLibraryTreeItem;}
QToolButton* getIconViewToolButton() {return mpIconViewToolButton;}
QToolButton* getDiagramViewToolButton() {return mpDiagramViewToolButton;}
QToolButton* getTextViewToolButton() {return mpTextViewToolButton;}
QToolButton* getDocumentationViewToolButton() {return mpDocumentationViewToolButton;}
void setDiagramGraphicsView(GraphicsView *pDiagramGraphicsView) {mpDiagramGraphicsView = pDiagramGraphicsView;}
GraphicsView* getDiagramGraphicsView() {return mpDiagramGraphicsView;}
void setIconGraphicsView(GraphicsView *pIconGraphicsView) {mpIconGraphicsView = pIconGraphicsView;}
GraphicsView* getIconGraphicsView() {return mpIconGraphicsView;}
UndoStack* getUndoStack() {return mpUndoStack;}
BaseEditor* getEditor() {return mpEditor;}
void setModelClassPathLabel(QString path) {mpModelClassPathLabel->setText(path);}
void setModelFilePathLabel(QString path) {mpModelFilePathLabel->setText(path);}
bool isLoadedWidgetComponents() {return mCreateModelWidgetComponents;}
void addInheritedClass(LibraryTreeItem *pLibraryTreeItem) {mInheritedClassesList.append(pLibraryTreeItem);}
void removeInheritedClass(LibraryTreeItem *pLibraryTreeItem) {mInheritedClassesList.removeOne(pLibraryTreeItem);}
void clearInheritedClasses() {mInheritedClassesList.clear();}
QList<LibraryTreeItem*> getInheritedClassesList() {return mInheritedClassesList;}
QMap<int, IconDiagramMap> getInheritedClassIconMap() {return mInheritedClassesIconMap;}
QMap<int, IconDiagramMap> getInheritedClassDiagramMap() {return mInheritedClassesDiagramMap;}
const QList<ElementInfo*> &getComponentsList() {return mElementsList;}
QMap<QString, QString> getExtendsModifiersMap(QString extendsClass);
QMap<QString, QString> getDerivedClassModifiersMap();
void fetchExtendsModifiers(QString extendsClass);
void reDrawModelWidgetInheritedClasses();
void drawModelCoOrdinateSystem(GraphicsView *pGraphicsView);
void drawModelIconDiagramShapes(QStringList shapes, GraphicsView *pGraphicsView, bool select);
ShapeAnnotation* createNonExistingInheritedShape(GraphicsView *pGraphicsView);
static ShapeAnnotation* createInheritedShape(ShapeAnnotation *pShapeAnnotation, GraphicsView *pGraphicsView);
Element* createInheritedComponent(Element *pComponent, GraphicsView *pGraphicsView);
LineAnnotation* createInheritedConnection(LineAnnotation *pConnectionLineAnnotation);
void loadElements();
void loadDiagramView();
void loadConnections();
void getModelConnections();
void addConnection(QStringList connectionList, QString connectionAnnotationString, bool addToOMC, bool select);
void createModelWidgetComponents();
ShapeAnnotation* drawOMSModelElement();
void addUpdateDeleteOMSElementIcon(const QString &iconPath);
Element* getConnectorComponent(Element *pConnectorComponent, QString connectorName);
void clearGraphicsViews();
void reDrawModelWidget();
bool validateText(LibraryTreeItem **pLibraryTreeItem);
bool modelicaEditorTextChanged(LibraryTreeItem **pLibraryTreeItem);
void updateChildClasses(LibraryTreeItem *pLibraryTreeItem);
bool omsimulatorEditorTextChanged();
void clearSelection();
void updateClassAnnotationIfNeeded();
void updateModelText();
void updateUndoRedoActions();
bool writeCoSimulationResultFile(QString fileName);
bool writeVisualXMLFile(QString fileName, bool canWriteVisualXMLFile = false);
void beginMacro(const QString &text);
void endMacro();
void updateViewButtonsBasedOnAccess();
void associateBusWithConnector(QString busName, QString connectorName);
void dissociateBusWithConnector(QString busName, QString connectorName);
void associateBusWithConnectors(QString busName);
QList<QVariant> toOMSensData();
void createOMSimulatorUndoCommand(const QString &commandText, const bool doSnapShot = true, const bool switchToEdited = true,
const QString oldEditedCref = QString(""), const QString newEditedCref = QString(""));
void createOMSimulatorRenameModelUndoCommand(const QString &commandText, const QString &cref, const QString &newCref);
private:
ModelWidgetContainer *mpModelWidgetContainer;
LibraryTreeItem *mpLibraryTreeItem;
QToolButton *mpIconViewToolButton;
QToolButton *mpDiagramViewToolButton;
QToolButton *mpTextViewToolButton;
QToolButton *mpDocumentationViewToolButton;
QButtonGroup *mpViewsButtonGroup;
Label *mpReadOnlyLabel;
Label *mpModelicaTypeLabel;
Label *mpViewTypeLabel;
Label *mpModelClassPathLabel;
Label *mpModelFilePathLabel;
QToolButton *mpFileLockToolButton;
GraphicsView *mpDiagramGraphicsView;
GraphicsScene *mpDiagramGraphicsScene;
GraphicsView *mpIconGraphicsView;
GraphicsScene *mpIconGraphicsScene;
UndoStack *mpUndoStack;
QUndoView *mpUndoView;
BaseEditor *mpEditor;
QStatusBar *mpModelStatusBar;
bool mComponentsLoaded;
bool mDiagramViewLoaded;
bool mConnectionsLoaded;
bool mCreateModelWidgetComponents;
QString mIconAnnotationString;
QString mDiagramAnnotationString;
bool mExtendsModifiersLoaded;
QMap<QString, QMap<QString, QString> > mExtendsModifiersMap;
bool mDerivedClassModifiersLoaded;
QMap<QString, QString> mDerivedClassModifiersMap;
QList<LibraryTreeItem*> mInheritedClassesList;
QMap<int, IconDiagramMap> mInheritedClassesIconMap;
QMap<int, IconDiagramMap> mInheritedClassesDiagramMap;
QList<ElementInfo*> mElementsList;
QStringList mElementsAnnotationsList;
QTimer mUpdateModelTimer;
void createUndoStack();
void handleCanUndoRedoChanged();
IconDiagramMap getIconDiagramMap(QString mapAnnotation);
void getModelInheritedClasses();
void drawModelInheritedClassShapes(ModelWidget *pModelWidget, StringHandler::ViewType viewType);
void getModelIconDiagramShapes(StringHandler::ViewType viewType);
void readCoOrdinateSystemFromInheritedClass(ModelWidget *pModelWidget, GraphicsView *pGraphicsView);
void drawModelInheritedClassComponents(ModelWidget *pModelWidget, StringHandler::ViewType viewType);
void getModelElements();
void drawModelIconElements();
void drawModelDiagramElements();
void drawModelInheritedClassConnections(ModelWidget *pModelWidget);
void getModelTransitions();
void getModelInitialStates();
void getMetaModelSubModels();
void getMetaModelConnections();
void detectMultipleDeclarations();
QString getCompositeModelName();
void getCompositeModelSubModels();
void getCompositeModelConnections();
void drawOMSModelIconElements();
void drawOMSModelDiagramElements();
void drawOMSElement(LibraryTreeItem *pLibraryTreeItem, const QString &annotation);
void drawOMSModelConnections();
void associateBusWithConnector(QString busName, QString connectorName, GraphicsView *pGraphicsView);
void dissociateBusWithConnector(QString busName, QString connectorName, GraphicsView *pGraphicsView);
void associateBusWithConnectors(Element *pBusComponent, GraphicsView *pGraphicsView);
static void removeInheritedClasses(LibraryTreeItem *pLibraryTreeItem);
private slots:
void showIconView(bool checked);
void showDiagramView(bool checked);
void showTextView(bool checked);
void updateModel();
public slots:
void makeFileWritAble();
void showDocumentationView();
bool compositeModelEditorTextChanged();
void handleCanUndoChanged(bool canUndo);
void handleCanRedoChanged(bool canRedo);
protected:
virtual void closeEvent(QCloseEvent *event) override;
};
void addCloseActionsToSubWindowSystemMenu(QMdiSubWindow *pMdiSubWindow);
class ModelWidgetContainer : public QMdiArea
{
Q_OBJECT
public:
ModelWidgetContainer(QWidget *pParent = 0);
void addModelWidget(ModelWidget *pModelWidget, bool checkPreferedView = true);
ModelWidget* getCurrentModelWidget();
ModelWidget* getModelWidget(const QString &className);
QMdiSubWindow* getCurrentMdiSubWindow();
QMdiSubWindow* getMdiSubWindow(ModelWidget *pModelWidget);
void setPreviousViewType(StringHandler::ViewType viewType) {mPreviousViewType = viewType;}
StringHandler::ViewType getPreviousViewType() {return mPreviousViewType;}
void setShowGridLines(bool On) {mShowGridLines = On;}
bool isShowGridLines() {return mShowGridLines;}
bool eventFilter(QObject *object, QEvent *event);
void changeRecentModelsListSelection(bool moveDown);
#if !defined(WITHOUT_OSG)
void updateThreeDViewer(ModelWidget *pModelWidget);
#endif
bool validateText();
void getOpenedModelWidgetsOfOMSimulatorModel(const QString &modelName, QStringList *pOpenedModelWidgetsList);
void getCurrentModelWidgetSelectedComponents(QStringList *pIconSelectedItemsList, QStringList *pDiagramSelectedItemsList);
void selectCurrentModelWidgetComponents(QStringList iconSelectedItemsList, QStringList diagramSelectedItemsList);
private:
StringHandler::ViewType mPreviousViewType;
bool mShowGridLines;
QDialog *mpModelSwitcherDialog;
QListWidget *mpRecentModelsList;
QMdiSubWindow *mpLastActiveSubWindow;
void loadPreviousViewType(ModelWidget *pModelWidget);
public slots:
bool openRecentModelWidget(QListWidgetItem *pListWidgetItem);
void currentModelWidgetChanged(QMdiSubWindow *pSubWindow);
void updateThreeDViewer(QMdiSubWindow *pSubWindow);
void saveModelWidget();
void saveAsModelWidget();
void saveTotalModelWidget();
void printModel();
void fitToDiagram();
void showSimulationParams();
void alignInterfaces();
void addSystem();
void addOrEditIcon();
void deleteIcon();
void addConnector();
void addBus();
void addTLMBus();
void addSubModel();
};
#endif // MODELWIDGETCONTAINER_H