Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into 3dviewer
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Jan 10, 2017
2 parents 0159c0b + 87791ed commit 92c7f2f
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 25 deletions.
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/Annotations/LineAnnotation.cpp
Expand Up @@ -640,6 +640,7 @@ void LineAnnotation::updateEndPoint(QPointF point)
mPoints.back() = point;
updateCornerItem(lastIndex);
/* update the 2nd point */
assert(secondLastIndex < mGeometries.size());
if (mGeometries[secondLastIndex] == ShapeAnnotation::HorizontalLine) {
mPoints[secondLastIndex] = QPointF(mPoints[secondLastIndex].x(), mPoints[secondLastIndex].y() + dy);
} else if (mGeometries[secondLastIndex] == ShapeAnnotation::VerticalLine) {
Expand Down
3 changes: 3 additions & 0 deletions OMEdit/OMEditGUI/Annotations/ShapePropertiesDialog.cpp
Expand Up @@ -828,6 +828,9 @@ bool ShapePropertiesDialog::applyShapeProperties()
LineAnnotation::LineType lineType = LineAnnotation::ShapeType;
if (mpLineAnnotation) {
lineType = mpLineAnnotation->getLineType();
if (lineType == LineAnnotation::ConnectionType) {
mpLineAnnotation->adjustGeometries();
}
}
// if nothing has changed then just simply return true.
if (mOldAnnotation.compare(mpShapeAnnotation->getOMCShapeAnnotation()) == 0) {
Expand Down
15 changes: 13 additions & 2 deletions OMEdit/OMEditGUI/Annotations/TextAnnotation.cpp
Expand Up @@ -398,7 +398,10 @@ QString TextAnnotation::getShapeAnnotation()
annotationString.append(QString("fontSize=").append(QString::number(mFontSize)));
}
// get the font name
if (!mFontName.isEmpty()) {
/* Ticket:4204
* Don't insert the default font name as it might be operating system specific.
*/
if (!mFontName.isEmpty() && mFontName.compare(Helper::systemFontInfo.family()) != 0) {
annotationString.append(QString("fontName=\"").append(mFontName).append("\""));
}
// get the font styles
Expand Down Expand Up @@ -453,7 +456,15 @@ void TextAnnotation::updateTextStringHelper(QRegExp regExp)
if ((!variable.isEmpty()) && (variable.compare("%%") != 0) && (variable.compare("%name") != 0) && (variable.compare("%class") != 0)) {
variable.remove("%");
if (!variable.isEmpty()) {
QString textValue = mpComponent->getParameterDisplayString(variable);
QString textValue;
/* Ticket:4204
* If we have extend component then call Component::getParameterDisplayString from root component.
*/
if (mpComponent->getComponentType() == Component::Extend) {
textValue = mpComponent->getRootParentComponent()->getParameterDisplayString(variable);
} else {
textValue = mpComponent->getRootParentComponent()->getParameterDisplayString(variable);
}
if (!textValue.isEmpty()) {
mTextString.replace(pos, regExp.matchedLength(), textValue);
} else { /* if the value of %\\W* is empty then remove the % sign. */
Expand Down
44 changes: 32 additions & 12 deletions OMEdit/OMEditGUI/Component/Component.cpp
Expand Up @@ -482,6 +482,11 @@ Component::Component(QString name, LibraryTreeItem *pLibraryTreeItem, QString tr
}
connect(this, SIGNAL(transformHasChanged()), SLOT(updatePlacementAnnotation()));
connect(this, SIGNAL(transformHasChanged()), SLOT(updateOriginItem()));
/* Ticket:4204
* If the child class use text annotation from base class then we need to call this
* since when the base class is created the child class doesn't exist.
*/
displayTextChangedRecursive();
}

Component::Component(LibraryTreeItem *pLibraryTreeItem, Component *pParentComponent)
Expand Down Expand Up @@ -598,6 +603,11 @@ Component::Component(Component *pComponent, GraphicsView *pGraphicsView)
connect(mpReferenceComponent, SIGNAL(displayTextChanged()), SIGNAL(displayTextChanged()));
connect(mpReferenceComponent, SIGNAL(changed()), SLOT(referenceComponentChanged()));
connect(mpReferenceComponent, SIGNAL(deleted()), SLOT(referenceComponentDeleted()));
/* Ticket:4204
* If the child class use text annotation from base class then we need to call this
* since when the base class is created the child class doesn't exist.
*/
displayTextChangedRecursive();
}

Component::Component(ComponentInfo *pComponentInfo, Component *pParentComponent)
Expand Down Expand Up @@ -1106,8 +1116,9 @@ QString Component::getParameterDisplayString(QString parameterName)
mpLibraryTreeItem->getModelWidget()->loadDiagramView();
foreach (Component *pComponent, mpLibraryTreeItem->getModelWidget()->getDiagramGraphicsView()->getComponentsList()) {
if (pComponent->getComponentInfo()->getName().compare(parameterName) == 0) {
if (displayString.isEmpty())
if (displayString.isEmpty()) {
displayString = pComponent->getComponentInfo()->getParameterValue(pOMCProxy, mpLibraryTreeItem->getNameStructure());
}
typeName = pComponent->getComponentInfo()->getClassName();
checkEnumerationDisplayString(displayString, typeName);
break;
Expand Down Expand Up @@ -1592,18 +1603,23 @@ void Component::updateConnections()
QString Component::getParameterDisplayStringFromExtendsModifiers(QString parameterName)
{
QString displayString = "";
foreach (Component *pComponent, mInheritedComponentsList) {
if (pComponent->getLibraryTreeItem()) {
QMap<QString, QString> extendsModifiersMap = pComponent->getLibraryTreeItem()->getModelWidget()->getExtendsModifiersMap(pComponent->getLibraryTreeItem()->getNameStructure());
displayString = extendsModifiersMap.value(parameterName, "");
/* Ticket:4204
* Get the extends modifiers of the class not the inherited class.
*/
if (mpLibraryTreeItem) {
foreach (Component *pComponent, mInheritedComponentsList) {
if (pComponent->getLibraryTreeItem()) {
QMap<QString, QString> extendsModifiersMap = mpLibraryTreeItem->getModelWidget()->getExtendsModifiersMap(pComponent->getLibraryTreeItem()->getNameStructure());
displayString = extendsModifiersMap.value(parameterName, "");
if (!displayString.isEmpty()) {
return displayString;
}
}
displayString = pComponent->getParameterDisplayStringFromExtendsModifiers(parameterName);
if (!displayString.isEmpty()) {
return displayString;
}
}
displayString = pComponent->getParameterDisplayStringFromExtendsModifiers(parameterName);
if (!displayString.isEmpty()) {
return displayString;
}
}
return displayString;
}
Expand All @@ -1625,9 +1641,13 @@ QString Component::getParameterDisplayStringFromExtendsParameters(QString parame
foreach (Component *pComponent, pInheritedComponent->getLibraryTreeItem()->getModelWidget()->getDiagramGraphicsView()->getComponentsList()) {
if (pComponent->getComponentInfo()->getName().compare(parameterName) == 0) {
OMCProxy *pOMCProxy = MainWindow::instance()->getOMCProxy();
if (pComponent->getLibraryTreeItem()) {
if (displayString.isEmpty())
displayString = pComponent->getComponentInfo()->getParameterValue(pOMCProxy, pComponent->getLibraryTreeItem()->getNameStructure());
/* Ticket:4204
* Look for the parameter value in the parameter containing class not in the parameter class.
*/
if (pInheritedComponent->getLibraryTreeItem()) {
if (displayString.isEmpty()) {
displayString = pComponent->getComponentInfo()->getParameterValue(pOMCProxy, pInheritedComponent->getLibraryTreeItem()->getNameStructure());
}
typeName = pComponent->getComponentInfo()->getClassName();
checkEnumerationDisplayString(displayString, typeName);
if (!(displayString.isEmpty() || typeName.isEmpty())) {
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -1883,7 +1883,7 @@ void GraphicsView::mouseDoubleClickEvent(QMouseEvent *event)
/* Double click on Component also end up here.
* But we don't have GraphicsView for the shapes inside the Component so we can go out of this block.
*/
if (pShapeAnnotation && pShapeAnnotation->getGraphicsView()) {
if (!isCreatingConnection() && pShapeAnnotation && pShapeAnnotation->getGraphicsView()) {
if (mpModelWidget->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::Modelica) {
pShapeAnnotation->showShapeProperties();
return;
Expand Down
26 changes: 17 additions & 9 deletions OMEdit/OMEditGUI/OMC/OMCProxy.cpp
Expand Up @@ -952,6 +952,10 @@ QString OMCProxy::getComponentModifierValue(QString className, QString name)
*/
bool OMCProxy::setComponentModifierValue(QString className, QString modifierName, QString modifierValue)
{
modifierValue = StringHandler::removeFirstLastQuotes(modifierValue);
if (StringHandler::containsSpace(modifierValue)) {
modifierValue = QString("\"%1\"").arg(modifierValue);
}
QString expression;
if (modifierValue.isEmpty()) {
expression = QString("setComponentModifierValue(%1, %2, $Code(()))").arg(className).arg(modifierName);
Expand All @@ -961,7 +965,7 @@ bool OMCProxy::setComponentModifierValue(QString className, QString modifierName
expression = QString("setComponentModifierValue(%1, %2, $Code(=%3))").arg(className).arg(modifierName).arg(modifierValue);
}
sendCommand(expression);
if (getResult().toLower().contains("ok")) {
if (getResult().toLower().compare("ok") == 0) {
return true;
} else {
QString msg = tr("Unable to set the component modifier value using command <b>%1</b>").arg(expression);
Expand Down Expand Up @@ -1016,6 +1020,10 @@ QString OMCProxy::getExtendsModifierValue(QString className, QString extendsClas

bool OMCProxy::setExtendsModifierValue(QString className, QString extendsClassName, QString modifierName, QString modifierValue)
{
modifierValue = StringHandler::removeFirstLastQuotes(modifierValue);
if (StringHandler::containsSpace(modifierValue)) {
modifierValue = QString("\"%1\"").arg(modifierValue);
}
QString expression;
if (modifierValue.isEmpty()) {
expression = QString("setExtendsModifierValue(%1, %2, %3, $Code(()))").arg(className).arg(extendsClassName).arg(modifierName);
Expand All @@ -1027,7 +1035,7 @@ bool OMCProxy::setExtendsModifierValue(QString className, QString extendsClassNa
.arg(modifierValue);
}
sendCommand(expression);
if (getResult().toLower().contains("ok")) {
if (getResult().toLower().compare("ok") == 0) {
return true;
} else {
QString msg = tr("Unable to set the extends modifier value using command <b>%1</b>").arg(expression);
Expand Down Expand Up @@ -1798,10 +1806,11 @@ bool OMCProxy::renameComponentInClass(QString className, QString oldName, QStrin
bool OMCProxy::updateConnection(QString from, QString to, QString className, QString annotation)
{
sendCommand("updateConnection(" + from + "," + to + "," + className + "," + annotation + ")");
if (getResult().contains("Ok"))
if (getResult().toLower().compare("ok") == 0) {
return true;
else
} else {
return false;
}
}

/*!
Expand Down Expand Up @@ -1857,7 +1866,7 @@ bool OMCProxy::setComponentComment(QString className, QString componentName, QSt
bool OMCProxy::setComponentDimensions(QString className, QString componentName, QString dimensions)
{
sendCommand("setComponentDimensions(" + className + "," + componentName + "," + dimensions + ")");
if (getResult().contains("Ok")) {
if (getResult().toLower().compare("ok") == 0) {
return true;
} else {
return false;
Expand All @@ -1879,7 +1888,7 @@ bool OMCProxy::addConnection(QString from, QString to, QString className, QStrin
} else {
sendCommand("addConnection(" + from + "," + to + "," + className + "," + annotation + ")");
}
if (getResult().contains("Ok")) {
if (getResult().toLower().compare("ok") == 0) {
return true;
} else {
return false;
Expand All @@ -1896,10 +1905,9 @@ bool OMCProxy::addConnection(QString from, QString to, QString className, QStrin
bool OMCProxy::deleteConnection(QString from, QString to, QString className)
{
sendCommand("deleteConnection(" + from + "," + to + "," + className + ")");
if (getResult().contains("Ok"))
if (getResult().toLower().compare("ok") == 0) {
return true;
else
{
} else {
printMessagesStringInternal();
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Util/Helper.cpp
Expand Up @@ -49,7 +49,7 @@ QString Helper::omFileTypes = "Modelica Files (*.mo)";
QString Helper::omnotebookFileTypes = "OMNotebook Files (*.onb *.onbz *.nb)";
QString Helper::ngspiceNetlistFileTypes = "ngspice Netlist Files (*.cir *.sp *.spice)";
QString Helper::imageFileTypes = "SVG (*.svg);;PNG image (*.png);;Windows BMP image (*.bmp);;TIFF (*.tiff)";
QString Helper::bitmapFileTypes = "PNG image (*.png);Windows BMP image (*.bmp);JPEG (*.jpg *.jpeg)";
QString Helper::bitmapFileTypes = "Image Files (*.png *.bmp *.jpg *.jpeg);;PNG image (*.png);;Windows BMP image (*.bmp);;JPEG (*.jpg *.jpeg)";
QString Helper::fmuFileTypes = "FMU Files (*.fmu)";
QString Helper::xmlFileTypes = "XML Files (*.xml)";
QString Helper::infoXmlFileTypes = "OM Info Files (*_info.json)";
Expand Down
16 changes: 16 additions & 0 deletions OMEdit/OMEditGUI/Util/StringHandler.cpp
Expand Up @@ -1607,3 +1607,19 @@ bool StringHandler::isFileWritAble(QString filePath)
return true;
}
}

/*!
* \brief StringHandler::containsSpace
* Returns true if string contains a space.
* \param str
* \return
*/
bool StringHandler::containsSpace(QString str)
{
for (int i = 0 ; i < str.size() ; i++) {
if (str.at(i).isSpace()) {
return true;
}
}
return false;
}
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/Util/StringHandler.h
Expand Up @@ -152,6 +152,7 @@ class StringHandler : public QObject
static QMap<int, int> getLeadingSpaces(QString contents);
static int getLeadingSpacesSize(QString str);
static bool isFileWritAble(QString filePath);
static bool containsSpace(QString str);
protected:
static QString mLastOpenDir;
};
Expand Down

0 comments on commit 92c7f2f

Please sign in to comment.