Skip to content

Commit

Permalink
Save the folder structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Nov 9, 2015
1 parent 07834a6 commit a8c7fb8
Show file tree
Hide file tree
Showing 12 changed files with 451 additions and 296 deletions.
167 changes: 89 additions & 78 deletions OMEdit/OMEditGUI/Component/Component.cpp
Expand Up @@ -322,8 +322,8 @@ Component::Component(QString name, LibraryTreeItem *pLibraryTreeItem, QString tr
createResizerItems();
setToolTip(tr("<b>%1</b> %2").arg(mpComponentInfo->getClassName()).arg(mpComponentInfo->getName()));
if (mpLibraryTreeItem) {
connect(mpLibraryTreeItem, SIGNAL(loaded(LibraryTreeItem*)), SLOT(reloadComponent()));
connect(mpLibraryTreeItem, SIGNAL(unLoaded(LibraryTreeItem*)), SLOT(reloadComponent()));
connect(mpLibraryTreeItem, SIGNAL(loaded(LibraryTreeItem*)), SLOT(handleLoaded()));
connect(mpLibraryTreeItem, SIGNAL(unLoaded(LibraryTreeItem*)), SLOT(handleUnloaded()));
}
connect(this, SIGNAL(transformHasChanged()), SLOT(updatePlacementAnnotation()));
connect(this, SIGNAL(transformHasChanged()), SLOT(updateOriginItem()));
Expand Down Expand Up @@ -420,8 +420,8 @@ Component::Component(Component *pComponent, GraphicsView *pGraphicsView)
setToolTip(tr("<b>%1</b> %2<br /><br />Component declared in %3").arg(mpComponentInfo->getClassName()).arg(mpComponentInfo->getName())
.arg(mpReferenceComponent->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->getNameStructure()));
if (mpLibraryTreeItem) {
connect(mpLibraryTreeItem, SIGNAL(loaded(LibraryTreeItem*)), SLOT(reloadComponent()));
connect(mpLibraryTreeItem, SIGNAL(unLoaded(LibraryTreeItem*)), SLOT(reloadComponent()));
connect(mpLibraryTreeItem, SIGNAL(loaded(LibraryTreeItem*)), SLOT(handleLoaded()));
connect(mpLibraryTreeItem, SIGNAL(unLoaded(LibraryTreeItem*)), SLOT(handleUnloaded()));
}
connect(mpReferenceComponent, SIGNAL(added()), SLOT(referenceComponentAdded()));
connect(mpReferenceComponent, SIGNAL(transformHasChanged()), SLOT(referenceComponentChanged()));
Expand Down Expand Up @@ -876,28 +876,30 @@ void Component::createClassInheritedShapes()
*/
void Component::createClassShapes(LibraryTreeItem *pLibraryTreeItem)
{
GraphicsView *pGraphicsView = pLibraryTreeItem->getModelWidget()->getIconGraphicsView();
if (pLibraryTreeItem->isConnector() && mpGraphicsView->getViewType() == StringHandler::Diagram &&
mComponentType == Component::Root && pLibraryTreeItem->getModelWidget()->getDiagramGraphicsView()->hasAnnotation()) {
pGraphicsView = pLibraryTreeItem->getModelWidget()->getDiagramGraphicsView();
}
foreach (ShapeAnnotation *pShapeAnnotation, pGraphicsView->getShapesList()) {
if (dynamic_cast<LineAnnotation*>(pShapeAnnotation)) {
mShapesList.append(new LineAnnotation(pShapeAnnotation, this));
} else if (dynamic_cast<PolygonAnnotation*>(pShapeAnnotation)) {
mShapesList.append(new PolygonAnnotation(pShapeAnnotation, this));
} else if (dynamic_cast<RectangleAnnotation*>(pShapeAnnotation)) {
mShapesList.append(new RectangleAnnotation(pShapeAnnotation, this));
} else if (dynamic_cast<EllipseAnnotation*>(pShapeAnnotation)) {
mShapesList.append(new EllipseAnnotation(pShapeAnnotation, this));
} else if (dynamic_cast<TextAnnotation*>(pShapeAnnotation)) {
mShapesList.append(new TextAnnotation(pShapeAnnotation, this));
} else if (dynamic_cast<BitmapAnnotation*>(pShapeAnnotation)) {
mShapesList.append(new BitmapAnnotation(pShapeAnnotation, this));
if (!pLibraryTreeItem->isNonExisting()) {
GraphicsView *pGraphicsView = pLibraryTreeItem->getModelWidget()->getIconGraphicsView();
if (pLibraryTreeItem->isConnector() && mpGraphicsView->getViewType() == StringHandler::Diagram &&
mComponentType == Component::Root && pLibraryTreeItem->getModelWidget()->getDiagramGraphicsView()->hasAnnotation()) {
pGraphicsView = pLibraryTreeItem->getModelWidget()->getDiagramGraphicsView();
}
foreach (ShapeAnnotation *pShapeAnnotation, pGraphicsView->getShapesList()) {
if (dynamic_cast<LineAnnotation*>(pShapeAnnotation)) {
mShapesList.append(new LineAnnotation(pShapeAnnotation, this));
} else if (dynamic_cast<PolygonAnnotation*>(pShapeAnnotation)) {
mShapesList.append(new PolygonAnnotation(pShapeAnnotation, this));
} else if (dynamic_cast<RectangleAnnotation*>(pShapeAnnotation)) {
mShapesList.append(new RectangleAnnotation(pShapeAnnotation, this));
} else if (dynamic_cast<EllipseAnnotation*>(pShapeAnnotation)) {
mShapesList.append(new EllipseAnnotation(pShapeAnnotation, this));
} else if (dynamic_cast<TextAnnotation*>(pShapeAnnotation)) {
mShapesList.append(new TextAnnotation(pShapeAnnotation, this));
} else if (dynamic_cast<BitmapAnnotation*>(pShapeAnnotation)) {
mShapesList.append(new BitmapAnnotation(pShapeAnnotation, this));
}
}
connect(pLibraryTreeItem, SIGNAL(shapeAdded(LibraryTreeItem*,ShapeAnnotation*,GraphicsView*)),
SLOT(handleShapeAdded()), Qt::UniqueConnection);
}
connect(pLibraryTreeItem, SIGNAL(shapeAdded(LibraryTreeItem*,ShapeAnnotation*,GraphicsView*)),
SLOT(handleShapeAdded()), Qt::UniqueConnection);
}

/*!
Expand All @@ -908,8 +910,8 @@ void Component::createClassInheritedComponents()
{
foreach (ModelWidget::InheritedClass *pInheritedClass, mpLibraryTreeItem->getModelWidget()->getInheritedClassesList()) {
createClassComponents(pInheritedClass->mpLibraryTreeItem, true);
connect(pInheritedClass->mpLibraryTreeItem, SIGNAL(loaded(LibraryTreeItem*)), SLOT(reloadComponent()), Qt::UniqueConnection);
connect(pInheritedClass->mpLibraryTreeItem, SIGNAL(unLoaded(LibraryTreeItem*)), SLOT(reloadComponent()), Qt::UniqueConnection);
connect(pInheritedClass->mpLibraryTreeItem, SIGNAL(loaded(LibraryTreeItem*)), SLOT(handleLoaded()), Qt::UniqueConnection);
connect(pInheritedClass->mpLibraryTreeItem, SIGNAL(unLoaded(LibraryTreeItem*)), SLOT(handleUnloaded()), Qt::UniqueConnection);
}
}

Expand All @@ -921,22 +923,24 @@ void Component::createClassInheritedComponents()
*/
void Component::createClassComponents(LibraryTreeItem *pLibraryTreeItem, bool inherited)
{
foreach (Component *pComponent, pLibraryTreeItem->getModelWidget()->getIconGraphicsView()->getComponentsList()) {
Component *pNewComponent = new Component(pComponent, mpGraphicsView, this);
if (inherited) {
mInheritedComponentsList.append(pNewComponent);
} else {
mComponentsList.append(pNewComponent);
if (!pLibraryTreeItem->isNonExisting()) {
foreach (Component *pComponent, pLibraryTreeItem->getModelWidget()->getIconGraphicsView()->getComponentsList()) {
Component *pNewComponent = new Component(pComponent, mpGraphicsView, this);
if (inherited) {
mInheritedComponentsList.append(pNewComponent);
} else {
mComponentsList.append(pNewComponent);
}
}
}
foreach (Component *pComponent, pLibraryTreeItem->getModelWidget()->getDiagramGraphicsView()->getComponentsList()) {
Component *pNewComponent = new Component(pComponent, mpGraphicsView, this);
// Set the Parent Item to 0 beacause we don't want to render Diagram components. We just want to store them for Parameters Dialog.
pNewComponent->setParentItem(0);
if (inherited) {
mInheritedComponentsList.append(pNewComponent);
} else {
mComponentsList.append(pNewComponent);
foreach (Component *pComponent, pLibraryTreeItem->getModelWidget()->getDiagramGraphicsView()->getComponentsList()) {
Component *pNewComponent = new Component(pComponent, mpGraphicsView, this);
// Set the Parent Item to 0 beacause we don't want to render Diagram components. We just want to store them for Parameters Dialog.
pNewComponent->setParentItem(0);
if (inherited) {
mInheritedComponentsList.append(pNewComponent);
} else {
mComponentsList.append(pNewComponent);
}
}
}
}
Expand Down Expand Up @@ -1135,58 +1139,25 @@ void Component::setOriginAndExtents()
}
}

void Component::updatePlacementAnnotation()
{
// Add component annotation.
LibraryTreeItem *pLibraryTreeItem = mpGraphicsView->getModelWidget()->getLibraryTreeItem();
if (pLibraryTreeItem->getLibraryType()== LibraryTreeItem::TLM) {
TLMEditor *pTLMEditor = dynamic_cast<TLMEditor*>(mpGraphicsView->getModelWidget()->getEditor());
pTLMEditor->updateSubModelPlacementAnnotation(mpComponentInfo->getName(), mTransformation.getVisible()? "true" : "false",
getTransformationOrigin(), getTransformationExtent(),
QString::number(mTransformation.getRotateAngle()));
} else {
OMCProxy *pOMCProxy = mpGraphicsView->getModelWidget()->getModelWidgetContainer()->getMainWindow()->getOMCProxy();
pOMCProxy->updateComponent(mpComponentInfo->getName(), mpComponentInfo->getClassName(),
mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getNameStructure(), getPlacementAnnotation());
}
/* When something is changed in the icon layer then update the LibraryTreeItem in the Library Browser */
if (mpGraphicsView->getViewType() == StringHandler::Icon) {
mpGraphicsView->getModelWidget()->getLibraryTreeItem()->handleIconUpdated();
}
}

/*!
* \brief Component::updateOriginItem
* Slot that updates the position of the component OriginItem.
*/
void Component::updateOriginItem()
{
if (mTransformation.hasOrigin()) {
mpOriginItem->setPos(mTransformation.getOrigin());
}
}

/*!
* \brief Component::reloadComponent
* Reloads a component.
*/
void Component::reloadComponent()
void Component::reloadComponent(bool loaded)
{
// clear all shapes & components
removeShapes();
removeInheritedComponents();
removeComponents();
if (mpLibraryTreeItem && (!mpLibraryTreeItem->getModelWidget() || mpLibraryTreeItem->getModelWidget()->isReloadNeeded())) {
if (loaded && mpLibraryTreeItem && !mpLibraryTreeItem->getModelWidget()) {
MainWindow *pMainWindow = mpGraphicsView->getModelWidget()->getModelWidgetContainer()->getMainWindow();
pMainWindow->getLibraryWidget()->getLibraryTreeModel()->showModelWidget(mpLibraryTreeItem, "", false);
}
if (!mpLibraryTreeItem) { // if built in type e.g Real, Boolean etc.
mpDefaultComponentRectangle->setVisible(true);
mpDefaultComponentText->setVisible(true);
update();
} else if (mpLibraryTreeItem->isNonExisting()) { // if class is non existing
} else if (mpLibraryTreeItem->isNonExisting()) { // if class is non existing
mpNonExistingComponentLine->setVisible(true);
update();
} else {
createClassInheritedShapes();
createClassShapes(mpLibraryTreeItem);
Expand All @@ -1200,13 +1171,53 @@ void Component::reloadComponent()
mpDefaultComponentText->setVisible(true);
}
}
update();
if (mpGraphicsView->getViewType() == StringHandler::Icon) {
mpGraphicsView->getModelWidget()->getLibraryTreeItem()->handleIconUpdated();
}
}
}

void Component::updatePlacementAnnotation()
{
// Add component annotation.
LibraryTreeItem *pLibraryTreeItem = mpGraphicsView->getModelWidget()->getLibraryTreeItem();
if (pLibraryTreeItem->getLibraryType()== LibraryTreeItem::TLM) {
TLMEditor *pTLMEditor = dynamic_cast<TLMEditor*>(mpGraphicsView->getModelWidget()->getEditor());
pTLMEditor->updateSubModelPlacementAnnotation(mpComponentInfo->getName(), mTransformation.getVisible()? "true" : "false",
getTransformationOrigin(), getTransformationExtent(),
QString::number(mTransformation.getRotateAngle()));
} else {
OMCProxy *pOMCProxy = mpGraphicsView->getModelWidget()->getModelWidgetContainer()->getMainWindow()->getOMCProxy();
pOMCProxy->updateComponent(mpComponentInfo->getName(), mpComponentInfo->getClassName(),
mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getNameStructure(), getPlacementAnnotation());
}
/* When something is changed in the icon layer then update the LibraryTreeItem in the Library Browser */
if (mpGraphicsView->getViewType() == StringHandler::Icon) {
mpGraphicsView->getModelWidget()->getLibraryTreeItem()->handleIconUpdated();
}
}

/*!
* \brief Component::updateOriginItem
* Slot that updates the position of the component OriginItem.
*/
void Component::updateOriginItem()
{
if (mTransformation.hasOrigin()) {
mpOriginItem->setPos(mTransformation.getOrigin());
}
}

void Component::handleLoaded()
{
reloadComponent(true);
}

void Component::handleUnloaded()
{
reloadComponent(false);
}

void Component::handleShapeAdded()
{
removeShapes();
Expand Down
4 changes: 3 additions & 1 deletion OMEdit/OMEditGUI/Component/Component.h
Expand Up @@ -243,6 +243,7 @@ class Component : public QObject, public QGraphicsItem
void hideResizerItems();
void getScale(qreal *sx, qreal *sy);
void setOriginAndExtents();
void reloadComponent(bool loaded);
signals:
void added();
void transformChange();
Expand All @@ -252,7 +253,8 @@ class Component : public QObject, public QGraphicsItem
public slots:
void updatePlacementAnnotation();
void updateOriginItem();
void reloadComponent();
void handleLoaded();
void handleUnloaded();
void handleShapeAdded();
void referenceComponentAdded();
void referenceComponentChanged();
Expand Down
6 changes: 3 additions & 3 deletions OMEdit/OMEditGUI/Editors/BaseEditor.cpp
Expand Up @@ -238,7 +238,7 @@ void BaseEditor::PlainTextEdit::lineNumberAreaPaintEvent(QPaintEvent *event)
QString number;
if (mpBaseEditor->getModelWidget() && mpBaseEditor->getModelWidget()->getLibraryTreeItem()->isInPackageOneFile() &&
mpBaseEditor->getModelWidget()->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::Modelica) {
number = QString::number(blockNumber + mpBaseEditor->getModelWidget()->getLibraryTreeItem()->getClassInformation().lineNumberStart);
number = QString::number(blockNumber + mpBaseEditor->getModelWidget()->getLibraryTreeItem()->mClassInformation.lineNumberStart);
} else {
number = QString::number(blockNumber + 1);
}
Expand Down Expand Up @@ -322,7 +322,7 @@ void BaseEditor::PlainTextEdit::goToLineNumber(int lineNumber)
{
if (mpBaseEditor->getModelWidget() && mpBaseEditor->getModelWidget()->getLibraryTreeItem()->isInPackageOneFile() &&
mpBaseEditor->getModelWidget()->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::Modelica) {
int lineNumberStart = mpBaseEditor->getModelWidget()->getLibraryTreeItem()->getClassInformation().lineNumberStart;
int lineNumberStart = mpBaseEditor->getModelWidget()->getLibraryTreeItem()->mClassInformation.lineNumberStart;
int lineNumberDifferenceFromStart = lineNumberStart - 1;
lineNumber -= lineNumberDifferenceFromStart;
}
Expand Down Expand Up @@ -1125,7 +1125,7 @@ int GotoLineDialog::exec()
{
if (mpBaseEditor->getModelWidget() && mpBaseEditor->getModelWidget()->getLibraryTreeItem()->isInPackageOneFile() &&
mpBaseEditor->getModelWidget()->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::Modelica) {
int lineNumberStart = mpBaseEditor->getModelWidget()->getLibraryTreeItem()->getClassInformation().lineNumberStart;
int lineNumberStart = mpBaseEditor->getModelWidget()->getLibraryTreeItem()->mClassInformation.lineNumberStart;
mpLineNumberLabel->setText(tr("Enter line number (%1 to %2):").arg(QString::number(lineNumberStart))
.arg(QString::number(mpBaseEditor->getPlainTextEdit()->blockCount() + lineNumberStart - 1)));
} else {
Expand Down

0 comments on commit a8c7fb8

Please sign in to comment.