Skip to content

Commit

Permalink
Added the facility for adding connections on components which have a …
Browse files Browse the repository at this point in the history
…connector array , now making the connection at a specified index.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@9532 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
abhinn kothari committed Jul 25, 2011
1 parent 867af12 commit df11aec
Show file tree
Hide file tree
Showing 9 changed files with 461 additions and 11 deletions.
6 changes: 3 additions & 3 deletions OMEdit/OMEditGUI/Component.cpp
Expand Up @@ -553,14 +553,14 @@ QVariant Component::itemChange(GraphicsItemChange change, const QVariant &value)
emit componentMoved();
// if user has changed the postion using the keyboard then update annotations
// if user changes the position with mouse we handle it in mouse events of graphicsview
if (!isMousePressed)
{
//if (!isMousePressed)
// {
updateAnnotationString();
// update connectors annotations that are associated to this component
emit componentPositionChanged();
ProjectTab *pProjectTab = mpGraphicsView->mpParentProjectTab;
pProjectTab->mpModelicaEditor->setText(mpOMCProxy->list(pProjectTab->mModelNameStructure));
}
// }
}
#if (QT_VERSION >= QT_VERSION_CHECK(4, 7, 0))
else if (change == QGraphicsItem::ItemRotationHasChanged)
Expand Down
25 changes: 25 additions & 0 deletions OMEdit/OMEditGUI/ComponentsProperties.cpp
Expand Up @@ -59,6 +59,8 @@ ComponentsProperties::ComponentsProperties(QString value)
this->mCasualityMap.insert("unspecified", "none");
this->mCasuality.clear();

this->mIndex="";
this->mIndexValue=0;
parseString(value);
}

Expand All @@ -69,6 +71,18 @@ void ComponentsProperties::parseString(QString value)

int index = 0;
QStringList list = StringHandler::getStrings(value);
mIndex = StringHandler::removeFirstLastCurlBrackets(list.at(list.size()-1));


bool ok;
if(mIndex.isEmpty())
mIndexValue=-1;
else if(mIndex=="n")
mIndexValue=-2;
else
mIndexValue=mIndex.toInt(&ok,10);



if (list.size() > 0)
this->mClassName = list.at(0);
Expand Down Expand Up @@ -202,3 +216,14 @@ bool ComponentsProperties::getOuter()
{
return mIsOuter;
}


int ComponentsProperties::getIndexValue()
{
return mIndexValue;
}

QString ComponentsProperties::getIndex()
{
return mIndex;
}
4 changes: 4 additions & 0 deletions OMEdit/OMEditGUI/ComponentsProperties.h
Expand Up @@ -42,6 +42,7 @@ class ComponentsProperties
public:
ComponentsProperties(QString value);
void parseString(QString value);
QString getIndex();
QString getClassName();
QString getName();
QString getComment();
Expand All @@ -50,13 +51,16 @@ class ComponentsProperties
bool getFlow();
bool getFinal();
bool getReplaceable();
int getIndexValue();
QString getCasuality();
bool getInner();
bool getOuter();
private:
QString mClassName;
QString mName;
QString mComment;
QString mIndex;
int mIndexValue;
bool mIsProtected;
bool mIsFinal;
bool mIsFlow;
Expand Down
191 changes: 187 additions & 4 deletions OMEdit/OMEditGUI/ConnectorWidget.cpp
Expand Up @@ -52,7 +52,10 @@ Connector::Connector(Component *pComponent, GraphicsView *pParentView, QGraphics
setZValue(-1.0);
this->updateStartPoint(mpStartComponent->mapToScene(mpStartComponent->boundingRect().center()));
this->mEndComponentConnected = false;
this->mConnectorIsArray=false;
this->mIsActive = false;
this->mpStartConnectorArrayMenu= new ConnectorArrayMenu(this,mpParentGraphicsView->mpParentProjectTab->mpParentProjectTabWidget->mpParentMainWindow);
this->mpConnectorArrayMenu= new ConnectorArrayMenu(this,mpParentGraphicsView->mpParentProjectTab->mpParentProjectTabWidget->mpParentMainWindow);
this->drawConnector();
}

Expand Down Expand Up @@ -179,6 +182,16 @@ void Connector::setEndComponent(Component *pComponent)
//this->setPassive();
}

void Connector::setConnectorisArray(bool isArray)
{
this->mConnectorIsArray = isArray;
}

void Connector::setStartConnectorisArray(bool isArray)
{
this->mStartConnectorIsArray = isArray;
}

//! Returns the number of lines in a connector.
int Connector::getNumberOfLines()
{
Expand All @@ -202,6 +215,17 @@ Component* Connector::getEndComponent()
return mpEndComponent;
}

bool Connector::getConnectorisArray()
{
return mConnectorIsArray;
}

bool Connector::getStartConnectorisArray()
{
return mStartConnectorIsArray;
}


//! Returns the line with specified number.
//! @param line is the number of the wanted line.
//! @see getThirdLastLine()
Expand Down Expand Up @@ -254,20 +278,36 @@ void Connector::updateConnectionAnnotationString()
if (getStartComponent()->mpParentComponent)
{
startIconName = QString(getStartComponent()->mpParentComponent->getName()).append(".");
if(this->getStartConnectorisArray()==false)
startIconCompName = getStartComponent()->mpComponentProperties->getName();
else
startIconCompName = getStartComponent()->mpComponentProperties->getName() + "[" + this->mpStartConnectorArrayMenu->getConnectorIndex() + "]";

}
else
{

if(this->getStartConnectorisArray()==false)
startIconCompName = getStartComponent()->getName();
else
startIconCompName = getStartComponent()->getName() + "[" + this->mpStartConnectorArrayMenu->getConnectorIndex() + "]";

}
if (getEndComponent()->mpParentComponent)
{
endIconName = QString(getEndComponent()->mpParentComponent->getName()).append(".");
if(this->getConnectorisArray()==false)
endIconCompName = getEndComponent()->mpComponentProperties->getName();
else
endIconCompName = getEndComponent()->mpComponentProperties->getName() + "[" + this->mpConnectorArrayMenu->getConnectorIndex() + "]";
}
else
{
if(this->getConnectorisArray()==false)
endIconCompName = getEndComponent()->getName();
else
endIconCompName = getEndComponent()->getName() + "[" + this->mpConnectorArrayMenu->getConnectorIndex() + "]";

}
// send the updateconnection command to omc
MainWindow *pMainWindow = mpParentGraphicsView->mpParentProjectTab->mpParentProjectTabWidget->mpParentMainWindow;
Expand Down Expand Up @@ -555,12 +595,14 @@ void ConnectorLine::setHovered()
//! Defines what shall happen if a mouse key is pressed while hovering a connector line.
void ConnectorLine::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
//isMousePressed=true;
QGraphicsLineItem::mousePressEvent(event);
}

//! Defines what shall happen if a mouse key is released while hovering a connector line.
void ConnectorLine::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
//isMousePressed=false;
QGraphicsLineItem::mouseReleaseEvent(event);
}

Expand Down Expand Up @@ -624,10 +666,17 @@ QVariant ConnectorLine::itemChange(GraphicsItemChange change, const QVariant &va
if (change == QGraphicsItem::ItemPositionHasChanged)
{
emit lineMoved(this->mLineNumber);
mpParentConnector->updateConnectionAnnotationString();
ProjectTab *pProjectTab = mpParentConnector->mpParentGraphicsView->mpParentProjectTab;
OMCProxy *pOMCProxy = mpParentConnector->mpParentGraphicsView->mpParentProjectTab->mpParentProjectTabWidget->mpParentMainWindow->mpOMCProxy;
pProjectTab->mpModelicaEditor->setText(pOMCProxy->list(pProjectTab->mModelNameStructure));
if (!isMousePressed)
{
mpParentConnector->updateConnectionAnnotationString();
// update connectors annotations that are associated to this component
ProjectTab *pProjectTab = mpParentConnector->mpParentGraphicsView->mpParentProjectTab;
OMCProxy *pOMCProxy = mpParentConnector->mpParentGraphicsView->mpParentProjectTab->mpParentProjectTabWidget->mpParentMainWindow->mpOMCProxy;
pProjectTab->mpModelicaEditor->setText(pOMCProxy->list(pProjectTab->mModelNameStructure));

}


}
return value;
}
Expand All @@ -650,3 +699,137 @@ void ConnectorLine::setLine(QPointF pos1, QPointF pos2)
QGraphicsLineItem::setLine(this->mapFromParent(pos1).x(),this->mapFromParent(pos1).y(),
this->mapFromParent(pos2).x(),this->mapFromParent(pos2).y());
}


ConnectorArrayMenu::ConnectorArrayMenu(Connector *pConnector,QWidget *pParent)
: QDialog(pParent, Qt::WindowTitleHint)
{
mpConnector = pConnector;
setMinimumSize(375, 140);
//setModal(true);

// Create the Text Box, File Dialog and Labels
mpIndexLabel = new QLabel;
mpIndexTextBox = new QLineEdit;


// Create the buttons
mpOkButton = new QPushButton(tr("OK"));
mpOkButton->setAutoDefault(true);
connect(mpOkButton, SIGNAL(pressed()), SLOT(addIndex()));
mpCancelButton = new QPushButton(tr("Cancel"));
mpCancelButton->setAutoDefault(false);
connect(mpCancelButton, SIGNAL(pressed()), SLOT(reject()));

mpButtonBox = new QDialogButtonBox(Qt::Horizontal);
mpButtonBox->addButton(mpOkButton, QDialogButtonBox::ActionRole);
mpButtonBox->addButton(mpCancelButton, QDialogButtonBox::ActionRole);

// Create a layout
QGridLayout *mainLayout = new QGridLayout;
mainLayout->addWidget(mpIndexLabel, 0, 0);
mainLayout->addWidget(mpIndexTextBox, 1, 0);

mainLayout->addWidget(mpButtonBox, 4, 0);

setLayout(mainLayout);
}

ConnectorArrayMenu::~ConnectorArrayMenu()
{

}

void ConnectorArrayMenu::show(int maxIndex)
{

setWindowTitle(QString(Helper::applicationName).append(" - Create New "));
mpIndexLabel->setText(" Index:");
mpIndexTextBox->setText(tr(""));
mpIndexTextBox->setFocus();
mMaxIndex=maxIndex;
setVisible(true);

}

QString ConnectorArrayMenu::getConnectorIndex()
{
return mConnectorIndex;
}

void ConnectorArrayMenu::setConnectorIndex(QString connectorIndex )
{
mConnectorIndex=connectorIndex;
}

void ConnectorArrayMenu::addIndex()
{
bool ok;
int index= mpIndexTextBox->text().toInt(&ok,10);

if(ok==true)
{
if(index>=0 && index<=mMaxIndex || index>=0 && mMaxIndex ==-2)
{

Component *pEndComponent = this->mpConnector->getEndComponent();
Component *pStartComponent = this->mpConnector->getStartComponent();
QString indexStr = QString::number(index);
this->setConnectorIndex(indexStr);


if(!pEndComponent)
accept();

else
{
this->mpConnector->mpParentGraphicsView->addConnectorForArray(pStartComponent,pEndComponent,index);
accept();
}
}
else
{
if(mMaxIndex==-2)
{
QMessageBox::critical(this, Helper::applicationName + " - Error",
GUIMessages::getMessage(GUIMessages::ENTER_VALID_INTEGER)
, tr("OK"));
}
else
{
QMessageBox::critical(this, Helper::applicationName + " - Error",
GUIMessages::getMessage(GUIMessages::ENTER_VALID_INTEGER).
arg("less than equal to"+QString::number(mMaxIndex)), tr("OK"));
}
return;
}
}
else
{
if(mMaxIndex==-2)
{
QMessageBox::critical(this, Helper::applicationName + " - Error",
GUIMessages::getMessage(GUIMessages::ENTER_VALID_INTEGER)
, tr("OK"));
}
else
{
QMessageBox::critical(this, Helper::applicationName + " - Error",
GUIMessages::getMessage(GUIMessages::ENTER_VALID_INTEGER).
arg("less than equal to"+QString::number(mMaxIndex)), tr("OK"));
}
return;
}

}

void ConnectorArrayMenu::reject()
{
Component *pEndComponent = this->mpConnector->getEndComponent();
Component *pStartComponent = this->mpConnector->getStartComponent();
this->mpConnector->mpParentGraphicsView->addConnectorForArray(pStartComponent,pEndComponent,-1);
QDialog::reject();

}


0 comments on commit df11aec

Please sign in to comment.