@@ -1297,6 +1297,78 @@ QString Component::getParameterDisplayString(QString parameterName)
12971297 return displayString;
12981298}
12991299
1300+ /* !
1301+ * \brief Component::getDerivedClassModifierValue
1302+ * Used to fetch the values of unit and displayUnit.
1303+ * \param modifierName
1304+ * \return
1305+ */
1306+ QString Component::getDerivedClassModifierValue (QString modifierName)
1307+ {
1308+ /* Get unit value
1309+ * First check if unit is defined with in the component modifier.
1310+ * If no unit is found then check it in the derived class modifier value.
1311+ * A derived class can be inherited, so look recursively.
1312+ */
1313+ OMCProxy *pOMCProxy = MainWindow::instance ()->getOMCProxy ();
1314+ QString className = mpGraphicsView->getModelWidget ()->getLibraryTreeItem ()->getNameStructure ();
1315+ QString modifierValue = mpComponentInfo->getModifiersMap (pOMCProxy, className, this ).value (modifierName);
1316+ if (modifierValue.isEmpty ()) {
1317+ if (!pOMCProxy->isBuiltinType (mpComponentInfo->getClassName ())) {
1318+ if (mpLibraryTreeItem) {
1319+ if (!mpLibraryTreeItem->getModelWidget ()) {
1320+ MainWindow::instance ()->getLibraryWidget ()->getLibraryTreeModel ()->showModelWidget (mpLibraryTreeItem, false );
1321+ }
1322+ modifierValue = mpLibraryTreeItem->getModelWidget ()->getDerivedClassModifiersMap ().value (modifierName);
1323+ }
1324+ if (modifierValue.isEmpty ()) {
1325+ modifierValue = getInheritedDerivedClassModifierValue (this , modifierName);
1326+ }
1327+ }
1328+ }
1329+ return StringHandler::removeFirstLastQuotes (modifierValue);
1330+ }
1331+
1332+ /* !
1333+ * \brief Component::getInheritedDerivedClassModifierValue
1334+ * Helper function for Component::getDerivedClassModifierValue()
1335+ * \param pComponent
1336+ * \param modifierName
1337+ * \return
1338+ */
1339+ QString Component::getInheritedDerivedClassModifierValue (Component *pComponent, QString modifierName)
1340+ {
1341+ MainWindow *pMainWindow = MainWindow::instance ();
1342+ OMCProxy *pOMCProxy = pMainWindow->getOMCProxy ();
1343+ QString modifierValue = " " ;
1344+ if (!pComponent->getLibraryTreeItem ()->getModelWidget ()) {
1345+ pMainWindow->getLibraryWidget ()->getLibraryTreeModel ()->showModelWidget (pComponent->getLibraryTreeItem (), false );
1346+ }
1347+ foreach (Component *pInheritedComponent, pComponent->getInheritedComponentsList ()) {
1348+ /* Ticket #4031
1349+ * Since we use the parent ComponentInfo for inherited classes so we should not use
1350+ * pInheritedComponent->getComponentInfo()->getClassName() to get the name instead we should use
1351+ * pInheritedComponent->getLibraryTreeItem()->getNameStructure() to get the correct name of inherited class.
1352+ * Also don't just return after reading from first inherited class. Check recursively.
1353+ */
1354+ if (!pOMCProxy->isBuiltinType (pInheritedComponent->getLibraryTreeItem ()->getNameStructure ())) {
1355+ if (pInheritedComponent->getLibraryTreeItem ()) {
1356+ if (!pInheritedComponent->getLibraryTreeItem ()->getModelWidget ()) {
1357+ pMainWindow->getLibraryWidget ()->getLibraryTreeModel ()->showModelWidget (pInheritedComponent->getLibraryTreeItem (), false );
1358+ }
1359+ modifierValue = pInheritedComponent->getLibraryTreeItem ()->getModelWidget ()->getDerivedClassModifiersMap ().value (modifierName);
1360+ }
1361+ if (modifierValue.isEmpty ()) {
1362+ modifierValue = getInheritedDerivedClassModifierValue (pInheritedComponent, modifierName);
1363+ }
1364+ if (!modifierValue.isEmpty ()) {
1365+ return StringHandler::removeFirstLastQuotes (modifierValue);
1366+ }
1367+ }
1368+ }
1369+ return " " ;
1370+ }
1371+
13001372/* !
13011373 * \brief Component::shapeAdded
13021374 * Called when a reference shape is added in its actual class.
@@ -1478,6 +1550,31 @@ void Component::setBusComponent(Component *pBusComponent)
14781550 setVisible (!isInBus ());
14791551}
14801552
1553+ /* !
1554+ * \brief Component::getComponentByName
1555+ * Finds the component by name.
1556+ * \param componentName
1557+ * \return
1558+ */
1559+ Component *Component::getComponentByName (const QString &componentName)
1560+ {
1561+ Component *pComponentFound = 0 ;
1562+ foreach (Component *pComponent, getComponentsList ()) {
1563+ if (pComponent->getComponentInfo () && pComponent->getName ().compare (componentName) == 0 ) {
1564+ pComponentFound = pComponent;
1565+ return pComponentFound;
1566+ }
1567+ }
1568+ /* if is not found in components list then look into the inherited components list. */
1569+ foreach (Component *pInheritedComponent, getInheritedComponentsList ()) {
1570+ pComponentFound = pInheritedComponent->getComponentByName (componentName);
1571+ if (pComponentFound) {
1572+ return pComponentFound;
1573+ }
1574+ }
1575+ return pComponentFound;
1576+ }
1577+
14811578/* !
14821579 * \brief Component::createNonExistingComponent
14831580 * Creates a non-existing component.
0 commit comments