Skip to content

Commit

Permalink
Fix the Text(textColor = ...) annotation & re-enable it on icons
Browse files Browse the repository at this point in the history
Belonging to [master]:
  - #142
  - OpenModelica/OMCompiler#3052
  • Loading branch information
atrosinenko authored and OpenModelica-Hudson committed Apr 16, 2019
1 parent d804419 commit 1add323
Show file tree
Hide file tree
Showing 11 changed files with 177 additions and 149 deletions.
2 changes: 2 additions & 0 deletions OMEdit/OMEdit/OMEditGUI/Annotations/ShapeAnnotation.cpp
Expand Up @@ -324,6 +324,8 @@ ShapeAnnotation::ShapeAnnotation(bool inheritedShape, GraphicsView *pGraphicsVie
createActions();
}

int ShapeAnnotation::maxTextLengthToShowOnLibraryIcon = 2;

/*!
* \brief ShapeAnnotation::setDefaults
* Sets the default values for the shape annotations. Defaults valued as defined in Modelica specification 3.2 are used.
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEdit/OMEditGUI/Annotations/ShapeAnnotation.h
Expand Up @@ -193,6 +193,7 @@ class ShapeAnnotation : public QObject, public QGraphicsItem, public GraphicItem
void emitChanged() {emit changed();}
void emitDeleted() {emit deleted();}
void emitPrepareGeometryChange() {prepareGeometryChange();}
static int maxTextLengthToShowOnLibraryIcon;
signals:
void updateReferenceShapes();
void added();
Expand Down
23 changes: 16 additions & 7 deletions OMEdit/OMEdit/OMEditGUI/Annotations/TextAnnotation.cpp
Expand Up @@ -160,7 +160,7 @@ void TextAnnotation::parseShapeAnnotation(QString annotation)
FilledShape::parseShapeAnnotation(annotation);
// parse the shape to get the list of attributes of Text.
QStringList list = StringHandler::getStrings(annotation);
if (list.size() < 11) {
if (list.size() < 12) {
return;
}
// 9th item of the list contains the extent points
Expand Down Expand Up @@ -188,12 +188,24 @@ void TextAnnotation::parseShapeAnnotation(QString annotation)
initUpdateTextString();
// 11th item of the list contains the fontSize.
mFontSize = list.at(10).toFloat();
// 12th item of the list contains the optional textColor, {-1, -1, -1} if not set
QStringList textColorList = StringHandler::getStrings(StringHandler::removeFirstLastCurlBrackets(list.at(11)));
if (textColorList.size() >= 3)
{
int red, green, blue = 0;
red = textColorList.at(0).toInt();
green = textColorList.at(1).toInt();
blue = textColorList.at(2).toInt();
if (red >= 0 && green >= 0 && blue >= 0) {
mLineColor = QColor (red, green, blue);
}
}
//Now comes the optional parameters; fontName and textStyle.
annotation = annotation.replace("{", "");
annotation = annotation.replace("}", "");
// parse the shape to get the list of attributes of Text Annotation.
list = StringHandler::getStrings(annotation);
int index = 19;
int index = 22;
mTextStyles.clear();
while(index < list.size()) {
QString annotationValue = StringHandler::removeFirstLastQuotes(list.at(index));
Expand Down Expand Up @@ -257,12 +269,9 @@ void TextAnnotation::paint(QPainter *painter, const QStyleOptionGraphicsItem *op
{
Q_UNUSED(option);
Q_UNUSED(widget);
//! @note We don't show text annotation that contains % for Library Icons. Only static text for functions are shown.
//! @note We don't show text annotation that contains % for Library Icons or if it is too long.
if (mpGraphicsView && mpGraphicsView->isRenderingLibraryPixmap()) {
if (mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getRestriction() != StringHandler::Function) {
return;
}
if (mOriginalTextString.contains("%")) {
if (mOriginalTextString.contains("%") || mOriginalTextString.length() > maxTextLengthToShowOnLibraryIcon) {
return;
}
} else if (mpComponent && mpComponent->getGraphicsView()->isRenderingLibraryPixmap()) {
Expand Down
17 changes: 15 additions & 2 deletions OMEdit/OMEdit/OMEditGUI/Options/OptionsDialog.cpp
Expand Up @@ -210,6 +210,11 @@ void OptionsDialog::readGeneralSettings()
if (mpSettings->contains("libraryIconSize")) {
mpGeneralSettingsPage->getLibraryIconSizeSpinBox()->setValue(mpSettings->value("libraryIconSize").toInt());
}
// read the max. text length to draw on a library icon
if (mpSettings->contains("libraryIconMaxTextLength")) {
ShapeAnnotation::maxTextLengthToShowOnLibraryIcon = mpSettings->value("libraryIconMaxTextLength").toInt(); // set cached value
}
mpGeneralSettingsPage->getLibraryIconTextLengthSpinBox()->setValue(ShapeAnnotation::maxTextLengthToShowOnLibraryIcon);
// read show protected classes
if (mpSettings->contains("showProtectedClasses")) {
mpGeneralSettingsPage->setShowProtectedClasses(mpSettings->value("showProtectedClasses").toBool());
Expand Down Expand Up @@ -961,6 +966,8 @@ void OptionsDialog::saveGeneralSettings()
mpSettings->setValue("activateAccessAnnotations", mpGeneralSettingsPage->getActivateAccessAnnotationsComboBox()->itemData(mpGeneralSettingsPage->getActivateAccessAnnotationsComboBox()->currentIndex()).toInt());
// save library icon size
mpSettings->setValue("libraryIconSize", mpGeneralSettingsPage->getLibraryIconSizeSpinBox()->value());
// save the max. text length to show on a library icon
mpSettings->setValue("libraryIconMaxTextLength", mpGeneralSettingsPage->getLibraryIconTextLengthSpinBox()->value());
// save show protected classes
mpSettings->setValue("showProtectedClasses", mpGeneralSettingsPage->getShowProtectedClasses());
// save show hidden classes
Expand Down Expand Up @@ -1802,6 +1809,10 @@ GeneralSettingsPage::GeneralSettingsPage(OptionsDialog *pOptionsDialog)
mpLibraryIconSizeSpinBox = new QSpinBox;
mpLibraryIconSizeSpinBox->setMinimum(16);
mpLibraryIconSizeSpinBox->setValue(24);
// library icon max. text length, value is set later
mpLibraryIconTextLengthLabel = new Label(tr("Max. Library Icon Text Length to Show: *"));
mpLibraryIconTextLengthSpinBox = new QSpinBox;
mpLibraryIconTextLengthSpinBox->setMinimum(0);
// show protected classes
mpShowProtectedClasses = new QCheckBox(tr("Show Protected Classes"));
// show hidden classes
Expand All @@ -1812,8 +1823,10 @@ GeneralSettingsPage::GeneralSettingsPage(OptionsDialog *pOptionsDialog)
pLibrariesBrowserLayout->setColumnStretch(1, 1);
pLibrariesBrowserLayout->addWidget(mpLibraryIconSizeLabel, 0, 0);
pLibrariesBrowserLayout->addWidget(mpLibraryIconSizeSpinBox, 0, 1);
pLibrariesBrowserLayout->addWidget(mpShowProtectedClasses, 1, 0, 1, 2);
pLibrariesBrowserLayout->addWidget(mpShowHiddenClasses, 2, 0, 1, 2);
pLibrariesBrowserLayout->addWidget(mpLibraryIconTextLengthLabel, 1, 0);
pLibrariesBrowserLayout->addWidget(mpLibraryIconTextLengthSpinBox, 1, 1);
pLibrariesBrowserLayout->addWidget(mpShowProtectedClasses, 2, 0, 1, 2);
pLibrariesBrowserLayout->addWidget(mpShowHiddenClasses, 3, 0, 1, 2);
mpLibrariesBrowserGroupBox->setLayout(pLibrariesBrowserLayout);
// Modeling View Mode
mpModelingViewModeGroupBox = new QGroupBox(tr("Default Modeling View Mode"));
Expand Down
3 changes: 3 additions & 0 deletions OMEdit/OMEdit/OMEditGUI/Options/OptionsDialog.h
Expand Up @@ -228,6 +228,7 @@ class GeneralSettingsPage : public QWidget
QCheckBox* getHideVariablesBrowserCheckBox() {return mpHideVariablesBrowserCheckBox;}
QComboBox* getActivateAccessAnnotationsComboBox() {return mpActivateAccessAnnotationsComboBox;}
QSpinBox* getLibraryIconSizeSpinBox() {return mpLibraryIconSizeSpinBox;}
QSpinBox* getLibraryIconTextLengthSpinBox() {return mpLibraryIconTextLengthSpinBox;}
void setShowProtectedClasses(bool value) {mpShowProtectedClasses->setChecked(value);}
bool getShowProtectedClasses() {return mpShowProtectedClasses->isChecked();}
void setShowHiddenClasses(bool value) {mpShowHiddenClasses->setChecked(value);}
Expand Down Expand Up @@ -263,6 +264,8 @@ class GeneralSettingsPage : public QWidget
QGroupBox *mpLibrariesBrowserGroupBox;
Label *mpLibraryIconSizeLabel;
QSpinBox *mpLibraryIconSizeSpinBox;
Label *mpLibraryIconTextLengthLabel;
QSpinBox *mpLibraryIconTextLengthSpinBox;
QCheckBox *mpShowProtectedClasses;
QCheckBox *mpShowHiddenClasses;
QGroupBox *mpModelingViewModeGroupBox;
Expand Down
2 changes: 1 addition & 1 deletion testsuite/openmodelica/interactive-API/Bug2871.mos
Expand Up @@ -84,7 +84,7 @@ instantiateModel(Modelica.Fluid.Examples.Tanks.ThreeTanks); getErrorString();
// 1
// Modelica.Fluid.Interfaces.PartialTwoPort
// "model"
// {-100.0,-100.0,100.0,100.0,true,0.1,2.0,2.0,{Polygon(true, {0.0, 0.0}, 0, {0, 128, 255}, {0, 128, 255}, LinePattern.Solid, FillPattern.Solid, 0.25, {{20, -70}, {60, -85}, {20, -100}, {20, -70}}, Smooth.None), Polygon(true, {0.0, 0.0}, 0, {255, 255, 255}, {255, 255, 255}, LinePattern.Solid, FillPattern.Solid, 0.25, {{20, -75}, {50, -85}, {20, -95}, {20, -75}}, Smooth.None), Line(true, {0.0, 0.0}, 0, {{55, -85}, {-60, -85}}, {0, 128, 255}, LinePattern.Solid, 0.25, {Arrow.None, Arrow.None}, 3, Smooth.None), Text(true, {0.0, 0.0}, 0, {0, 0, 255}, {0, 0, 0}, LinePattern.Solid, FillPattern.None, 0.25, {{-149, -114}, {151, -154}}, "%name", 0, TextAlignment.Center), Ellipse(false, {0.0, 0.0}, 0, {0, 0, 0}, {0, 0, 0}, LinePattern.Solid, FillPattern.Solid, 0.25, {{-110, 26}, {-90, -24}}, 0, 360), Ellipse(false, {0.0, 0.0}, 0, {0, 0, 0}, {0, 0, 0}, LinePattern.Solid, FillPattern.Solid, 0.25, {{90, 25}, {110, -25}}, 0, 360)}}
// {-100.0,-100.0,100.0,100.0,true,0.1,2.0,2.0,{Polygon(true, {0.0, 0.0}, 0, {0, 128, 255}, {0, 128, 255}, LinePattern.Solid, FillPattern.Solid, 0.25, {{20, -70}, {60, -85}, {20, -100}, {20, -70}}, Smooth.None), Polygon(true, {0.0, 0.0}, 0, {255, 255, 255}, {255, 255, 255}, LinePattern.Solid, FillPattern.Solid, 0.25, {{20, -75}, {50, -85}, {20, -95}, {20, -75}}, Smooth.None), Line(true, {0.0, 0.0}, 0, {{55, -85}, {-60, -85}}, {0, 128, 255}, LinePattern.Solid, 0.25, {Arrow.None, Arrow.None}, 3, Smooth.None), Text(true, {0.0, 0.0}, 0, {0, 0, 255}, {0, 0, 0}, LinePattern.Solid, FillPattern.None, 0.25, {{-149, -114}, {151, -154}}, "%name", 0, {-1, -1, -1}, TextAlignment.Center), Ellipse(false, {0.0, 0.0}, 0, {0, 0, 0}, {0, 0, 0}, LinePattern.Solid, FillPattern.Solid, 0.25, {{-110, 26}, {-90, -24}}, 0, 360), Ellipse(false, {0.0, 0.0}, 0, {0, 0, 0}, {0, 0, 0}, LinePattern.Solid, FillPattern.Solid, 0.25, {{90, 25}, {110, -25}}, 0, 360)}}
// 0
// true
// {{"Modelica.Fluid.System","system","System wide properties", "public", "false", "false", "false", "false", "unspecified", "outer", "unspecified","{}"},{"Boolean","allowFlowReversal","= true to allow flow reversal, false restricts to design direction (port_a -> port_b)", "public", "false", "false", "false", "false", "parameter", "none", "unspecified","{}"},{"Modelica.Fluid.Interfaces.FluidPort_a","port_a","Fluid connector a (positive design flow direction is from port_a to port_b)", "public", "false", "false", "false", "false", "unspecified", "none", "unspecified","{}"},{"Modelica.Fluid.Interfaces.FluidPort_b","port_b","Fluid connector b (positive design flow direction is from port_a to port_b)", "public", "false", "false", "false", "false", "unspecified", "none", "unspecified","{}"},{"Boolean","port_a_exposesState","= true if port_a exposes the state of a fluid volume", "protected", "false", "false", "false", "false", "parameter", "none", "unspecified","{}"},{"Boolean","port_b_exposesState","= true if port_b.p exposes the state of a fluid volume", "protected", "false", "false", "false", "false", "parameter", "none", "unspecified","{}"},{"Boolean","showDesignFlowDirection","= false to hide the arrow in the model icon", "protected", "false", "false", "false", "false", "parameter", "none", "unspecified","{}"}}
Expand Down
Expand Up @@ -10,6 +10,6 @@ getIconAnnotation(Buildings.Fluid.Movers.BaseClasses.PartialFlowMachine);getErro
// ""
// true
// ""
// {-100.0,-100.0,100.0,100.0,false,0.1,2.0,2.0,{Line(true, {0.0, 0.0}, 0, {{0, 50}, {100, 50}}, {0, 0, 0}, LinePattern.Solid, 0.25, {Arrow.None, Arrow.None}, 3, Smooth.None), Line(true, {0.0, 0.0}, 0, {{0, 80}, {100, 80}}, {0, 0, 0}, LinePattern.Solid, 0.25, {Arrow.None, Arrow.None}, 3, Smooth.None), Line(false, {0.0, 0.0}, 0, {{0, 100}, {0, 40}}, {0, 0, 0}, LinePattern.Solid, 0.25, {Arrow.None, Arrow.None}, 3, Smooth.None), Rectangle(true, {0.0, 0.0}, 0, {0, 0, 0}, {0, 127, 255}, LinePattern.Solid, FillPattern.HorizontalCylinder, 0.25, BorderPattern.None, {{-100, 16}, {100, -14}}, 0), Ellipse(true, {0.0, 0.0}, 0, {0, 0, 0}, {0, 100, 199}, LinePattern.Solid, FillPattern.Sphere, 0.25, {{-58, 50}, {54, -58}}, 0, 360), Polygon(true, {0.0, 0.0}, 0, {0, 0, 0}, {255, 255, 255}, LinePattern.None, FillPattern.HorizontalCylinder, 0.25, {{0, 50}, {0, -56}, {54, 2}, {0, 50}}, Smooth.None), Ellipse(true, {0.0, 0.0}, 0, {0, 0, 0}, {0, 100, 199}, LinePattern.Solid, FillPattern.Sphere, 0.25, {{4, 14}, {34, -16}}, 0, 360), Rectangle(true, {0.0, 0.0}, 0, {0, 0, 0}, {135, 135, 135}, LinePattern.Solid, FillPattern.Solid, 0.25, BorderPattern.None, {{-34, 40}, {32, 100}}, 0), Ellipse(true, {0.0, 0.0}, 0, {0, 0, 0}, {135, 135, 135}, LinePattern.Solid, FillPattern.Solid, 0.25, {{-34, 100}, {32, 40}}, 0, 360), Text(true, {0.0, 0.0}, 0, {0, 0, 0}, {135, 135, 135}, LinePattern.Solid, FillPattern.Solid, 0.25, {{-22, 92}, {20, 46}}, "M", 0, {TextStyle.Bold}, TextAlignment.Center), Text(true, {0.0, 0.0}, 0, {0, 0, 127}, {0, 0, 0}, LinePattern.Solid, FillPattern.None, 0.25, {{64, 98}, {114, 84}}, "P", 0, TextAlignment.Center)}}
// {-100.0,-100.0,100.0,100.0,false,0.1,2.0,2.0,{Line(true, {0.0, 0.0}, 0, {{0, 50}, {100, 50}}, {0, 0, 0}, LinePattern.Solid, 0.25, {Arrow.None, Arrow.None}, 3, Smooth.None), Line(true, {0.0, 0.0}, 0, {{0, 80}, {100, 80}}, {0, 0, 0}, LinePattern.Solid, 0.25, {Arrow.None, Arrow.None}, 3, Smooth.None), Line(false, {0.0, 0.0}, 0, {{0, 100}, {0, 40}}, {0, 0, 0}, LinePattern.Solid, 0.25, {Arrow.None, Arrow.None}, 3, Smooth.None), Rectangle(true, {0.0, 0.0}, 0, {0, 0, 0}, {0, 127, 255}, LinePattern.Solid, FillPattern.HorizontalCylinder, 0.25, BorderPattern.None, {{-100, 16}, {100, -14}}, 0), Ellipse(true, {0.0, 0.0}, 0, {0, 0, 0}, {0, 100, 199}, LinePattern.Solid, FillPattern.Sphere, 0.25, {{-58, 50}, {54, -58}}, 0, 360), Polygon(true, {0.0, 0.0}, 0, {0, 0, 0}, {255, 255, 255}, LinePattern.None, FillPattern.HorizontalCylinder, 0.25, {{0, 50}, {0, -56}, {54, 2}, {0, 50}}, Smooth.None), Ellipse(true, {0.0, 0.0}, 0, {0, 0, 0}, {0, 100, 199}, LinePattern.Solid, FillPattern.Sphere, 0.25, {{4, 14}, {34, -16}}, 0, 360), Rectangle(true, {0.0, 0.0}, 0, {0, 0, 0}, {135, 135, 135}, LinePattern.Solid, FillPattern.Solid, 0.25, BorderPattern.None, {{-34, 40}, {32, 100}}, 0), Ellipse(true, {0.0, 0.0}, 0, {0, 0, 0}, {135, 135, 135}, LinePattern.Solid, FillPattern.Solid, 0.25, {{-34, 100}, {32, 40}}, 0, 360), Text(true, {0.0, 0.0}, 0, {0, 0, 0}, {135, 135, 135}, LinePattern.Solid, FillPattern.Solid, 0.25, {{-22, 92}, {20, 46}}, "M", 0, {-1, -1, -1}, {TextStyle.Bold}, TextAlignment.Center), Text(true, {0.0, 0.0}, 0, {0, 0, 127}, {0, 0, 0}, LinePattern.Solid, FillPattern.None, 0.25, {{64, 98}, {114, 84}}, "P", 0, {-1, -1, -1}, TextAlignment.Center)}}
// ""
// endResult
2 changes: 1 addition & 1 deletion testsuite/openmodelica/interactive-API/IllegalGraphics.mos
Expand Up @@ -6,7 +6,7 @@ getIconAnnotation(IllegalGraphics); getErrorString();
// Result:
// true
// ""
// {-100.0,-100.0,100.0,100.0,false,0.1,2.0,2.0,{Ellipse(true, {0.0, 0.0}, 0, {85, 170, 255}, {0, 0, 0}, LinePattern.Solid, FillPattern.None, 0.25, {{-60, -55}, {-30, -25}}, 0, 360), Ellipse(true, {0.0, 0.0}, 0, {85, 170, 255}, {0, 0, 0}, LinePattern.Dash, FillPattern.None, 0.25, {{-68, 10}, {68, -10}}, 0, 360), Text(true, {0.0, 0.0}, 0, {0, 0, 255}, {0, 0, 0}, LinePattern.Solid, FillPattern.None, 0.25, {{-100, 96}, {100, 60}}, "%name", 0, TextAlignment.Center)}}
// {-100.0,-100.0,100.0,100.0,false,0.1,2.0,2.0,{Ellipse(true, {0.0, 0.0}, 0, {85, 170, 255}, {0, 0, 0}, LinePattern.Solid, FillPattern.None, 0.25, {{-60, -55}, {-30, -25}}, 0, 360), Ellipse(true, {0.0, 0.0}, 0, {85, 170, 255}, {0, 0, 0}, LinePattern.Dash, FillPattern.None, 0.25, {{-68, 10}, {68, -10}}, 0, 360), Text(true, {0.0, 0.0}, 0, {0, 0, 255}, {0, 0, 0}, LinePattern.Solid, FillPattern.None, 0.25, {{-100, 96}, {100, 60}}, "%name", 0, {-1, -1, -1}, TextAlignment.Center)}}
// "[openmodelica/interactive-API/IllegalGraphics.mo:3:5-4:224:writable] Error: Function Ellipse has no parameter named linePattern.
// "
// endResult
Expand Up @@ -40,6 +40,6 @@ getIconAnnotation(IconWithValues.Component); getErrorString();
// ""
// ""
// ""
// {-100.0,-100.0,100.0,100.0,true,0.1,2.0,2.0,{Rectangle({false, neg}, {0, 0}, 0, {0, 0, 0}, {0, 0, 0}, LinePattern.Solid, FillPattern.None, 0.25, BorderPattern.None, {{-95, 95}, {95, -95}}, 0), Text(true, {-55, 35}, 0, {0, 0, 0}, {0, 0, 0}, LinePattern.Solid, FillPattern.None, 0.25, {{-35, 15}, {50, -30}}, "x = ", 0, TextAlignment.Center), Text(true, {-55, 35}, 0, {0, 0, 0}, {0, 0, 0}, LinePattern.Solid, FillPattern.None, 0.25, {{50, 15}, {150, -30}}, {"x", x}, 0, TextAlignment.Center), Text({true, pos}, {-55, -30}, 0, {0, 0, 0}, {0, 0, 0}, LinePattern.Solid, FillPattern.None, 0.25, {{-35, 15}, {150, -30}}, {"%y", y, 3}, 0, TextAlignment.Center), Text({false, neg}, {-55, -30}, 0, {255, 0, 0}, {0, 0, 0}, LinePattern.Solid, FillPattern.None, 0.25, {{-35, 15}, {150, -30}}, {"%y", y, 3}, 0, TextAlignment.Center)}}
// {-100.0,-100.0,100.0,100.0,true,0.1,2.0,2.0,{Rectangle({false, neg}, {0, 0}, 0, {0, 0, 0}, {0, 0, 0}, LinePattern.Solid, FillPattern.None, 0.25, BorderPattern.None, {{-95, 95}, {95, -95}}, 0), Text(true, {-55, 35}, 0, {0, 0, 0}, {0, 0, 0}, LinePattern.Solid, FillPattern.None, 0.25, {{-35, 15}, {50, -30}}, "x = ", 0, {-1, -1, -1}, TextAlignment.Center), Text(true, {-55, 35}, 0, {0, 0, 0}, {0, 0, 0}, LinePattern.Solid, FillPattern.None, 0.25, {{50, 15}, {150, -30}}, {"x", x}, 0, {-1, -1, -1}, TextAlignment.Center), Text({true, pos}, {-55, -30}, 0, {0, 0, 0}, {0, 0, 0}, LinePattern.Solid, FillPattern.None, 0.25, {{-35, 15}, {150, -30}}, {"%y", y, 3}, 0, {-1, -1, -1}, TextAlignment.Center), Text({false, neg}, {-55, -30}, 0, {255, 0, 0}, {0, 0, 0}, LinePattern.Solid, FillPattern.None, 0.25, {{-35, 15}, {150, -30}}, {"%y", y, 3}, 0, {-1, -1, -1}, TextAlignment.Center)}}
// ""
// endResult

0 comments on commit 1add323

Please sign in to comment.