Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- getDefaultComponentName and getDefaultComponentPrefixes now supported.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@9941 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Sep 26, 2011
1 parent 85127e4 commit fa183e9
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 32 deletions.
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/Helper.cpp
Expand Up @@ -227,6 +227,8 @@ QString GUIMessages::getMessage(int type)
return "Are you sure you want to delete '%1'? Everything contained inside this Package will also be deleted.";
case DELETE_MSG:
return "Are you sure you want to delete '%1'?";
case INNER_MODEL_NAME_CHANGED:
return "A component with the name %1 already exists. The name is changed from %1 to %2.\nThis is probably wrong because the component is decalred as %3.";
default:
return "";
}
Expand Down
3 changes: 2 additions & 1 deletion OMEdit/OMEditGUI/Helper.h
Expand Up @@ -189,7 +189,8 @@ class GUIMessages
ENTER_VALID_INTEGER,
ITEM_DROPPED_ON_ITSELF,
DELETE_PACKAGE_MSG,
DELETE_MSG
DELETE_MSG,
INNER_MODEL_NAME_CHANGED
};

static QString getMessage(int type);
Expand Down
18 changes: 18 additions & 0 deletions OMEdit/OMEditGUI/OMCProxy.cpp
Expand Up @@ -1183,6 +1183,24 @@ bool OMCProxy::addClassAnnotation(QString className, QString annotation)
return false;
}

QString OMCProxy::getDefaultComponentName(QString className)
{
sendCommand("getDefaultComponentName(" + className + ")");
if (getResult().compare("{}") == 0)
return QString();

return StringHandler::unparse(getResult());
}

QString OMCProxy::getDefaultComponentPrefixes(QString className)
{
sendCommand("getDefaultComponentPrefixes(" + className + ")");
if (getResult().compare("{}") == 0)
return QString();

return StringHandler::unparse(getResult());
}

bool OMCProxy::addComponent(QString name, QString className, QString modelName)
{
sendCommand("addComponent(" + name + ", " + className + "," + modelName + ")");
Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/OMCProxy.h
Expand Up @@ -144,6 +144,8 @@ class OMCProxy : public QObject
QString list(QString className);
QString instantiateModel(QString className);
bool addClassAnnotation(QString className, QString annotation);
QString getDefaultComponentName(QString className);
QString getDefaultComponentPrefixes(QString className);
bool addComponent(QString name, QString className, QString modelName);
bool deleteComponent(QString name, QString modelName);
bool renameComponent(QString modelName, QString oldName, QString newName);
Expand Down
83 changes: 52 additions & 31 deletions OMEdit/OMEditGUI/ProjectTabWidget.cpp
Expand Up @@ -219,12 +219,34 @@ void GraphicsView::dropEvent(QDropEvent *event)
dataStream >> name >> classname >> type;

MainWindow *pMainWindow = mpParentProjectTab->mpParentProjectTabWidget->mpParentMainWindow;

//item not to be dropped on itself
name = StringHandler::getLastWordAfterDot(name);
if (name != mpParentProjectTab->mModelName)
{
name = getUniqueComponentName(name.toLower());
// get the model defaultComponentPrefixes
QString defaultPrefix = pMainWindow->mpOMCProxy->getDefaultComponentPrefixes(classname);
// get the model defaultComponentName
QString defaultName = pMainWindow->mpOMCProxy->getDefaultComponentName(classname);
if (defaultName.isEmpty())
{
name = getUniqueComponentName(name.toLower());
}
else
{
if (checkComponentName(defaultName))
name = defaultName;
else
{
name = getUniqueComponentName(name.toLower());
// show the information to the user if we have changed the name of some inner component.
if (defaultPrefix.compare("inner") == 0)
{
pMainWindow->mpMessageWidget->printGUIWarningMessage(
GUIMessages::getMessage(GUIMessages::INNER_MODEL_NAME_CHANGED).arg(defaultName).arg(name)
.arg(defaultPrefix));
}
}
}
// if dropping an item on the diagram layer
if (mIconType == StringHandler::DIAGRAM)
{
Expand Down Expand Up @@ -399,11 +421,11 @@ Component* GraphicsView::getComponentObject(QString componentName)
QString GraphicsView::getUniqueComponentName(QString iconName, int number)
{
QString name;
name = iconName + QString::number(number);
name = QString(iconName).append(QString::number(number));

foreach (Component *icon, mComponentsList)
{
if (icon->getName() == name)
if (icon->getName().compare(name, Qt::CaseSensitive) == 0)
{
name = getUniqueComponentName(iconName, ++number);
break;
Expand All @@ -416,7 +438,7 @@ bool GraphicsView::checkComponentName(QString iconName)
{
foreach (Component *icon, mComponentsList)
{
if (icon->getName() == iconName)
if (icon->getName().compare(iconName, Qt::CaseSensitive) == 0)
{
return false;
}
Expand Down Expand Up @@ -755,41 +777,40 @@ void GraphicsView::createMenus()

}


//pasting the required copied component or a selection in the present view
//non functional currently, only works for a single component
void GraphicsView::pasteComponent()
{

QClipboard *clipboard = QApplication::clipboard();
QClipboard *clipboard = QApplication::clipboard();

if(!clipboard->text().isEmpty())
{
//GraphicsView *pGraphicsView = qobject_cast<GraphicsView*>(const_cast<QObject*>(sender()));
Component *oldComponent = getComponentObject(clipboard->text());
Component *newComponent;
QString name = getUniqueComponentName(oldComponent->getName().toLower());
if(!clipboard->text().isEmpty())
{
//GraphicsView *pGraphicsView = qobject_cast<GraphicsView*>(const_cast<QObject*>(sender()));
Component *oldComponent = getComponentObject(clipboard->text());
Component *newComponent;
QString name = getUniqueComponentName(oldComponent->getName().toLower());

//QPointF point;
QPointF point (mapToScene(this->pos()));
//QPointF point;
QPointF point (mapToScene(this->pos()));

//point= QPointF((this->pos().x()) +1.0 ,(this->pos().y()) +1.0);
newComponent = new Component(oldComponent,name,point,oldComponent->mType,oldComponent->getIsConnector(),this);
// remove the component from the scene
//mpGraphicsView->scene()->removeItem(this);
// if the signal is not send by graphicsview then call addclassannotation
//if (!pGraphicsView)
// {
// if (mpGraphicsView->mIconType == StringHandler::ICON)
//point= QPointF((this->pos().x()) +1.0 ,(this->pos().y()) +1.0);
newComponent = new Component(oldComponent,name,point,oldComponent->mType,oldComponent->getIsConnector(),this);
// remove the component from the scene
//mpGraphicsView->scene()->removeItem(this);
// if the signal is not send by graphicsview then call addclassannotation
//if (!pGraphicsView)
// {
// if (mpGraphicsView->mIconType == StringHandler::ICON)
// mpGraphicsView->addClassAnnotation();
// }
// delete(this);
this->addComponentObject(newComponent);
}
else
{
return ;
}
// }
// delete(this);
this->addComponentObject(newComponent);
}
else
{
return ;
}
}

void GraphicsView::createLineShape(QPointF point)
Expand Down

0 comments on commit fa183e9

Please sign in to comment.