15#include <KactusAPI/KactusAPI.h>
40#include <IPXACTmodels/common/ConfigurableVLNVReference.h>
41#include <IPXACTmodels/common/validators/ParameterValidator.h>
43#include <IPXACTmodels/Component/Component.h>
44#include <IPXACTmodels/Component/Port.h>
45#include <IPXACTmodels/Component/View.h>
46#include <IPXACTmodels/Component/MemoryMap.h>
47#include <IPXACTmodels/Component/PortMap.h>
48#include <IPXACTmodels/Component/AddressBlock.h>
49#include <IPXACTmodels/Component/MemoryBlockBase.h>
50#include <IPXACTmodels/Component/RegisterBase.h>
51#include <IPXACTmodels/Component/Register.h>
52#include <IPXACTmodels/Component/Field.h>
53#include <IPXACTmodels/Component/validators/FieldValidator.h>
54#include <IPXACTmodels/Component/validators/EnumeratedValueValidator.h>
55#include <IPXACTmodels/Component/validators/RegisterValidator.h>
56#include <IPXACTmodels/Component/validators/RegisterFileValidator.h>
57#include <IPXACTmodels/Component/validators/AddressBlockValidator.h>
58#include <IPXACTmodels/Component/validators/SubspaceMapValidator.h>
59#include <IPXACTmodels/Component/validators/MemoryMapValidator.h>
60#include <IPXACTmodels/Component/validators/FileSetValidator.h>
61#include <IPXACTmodels/Component/validators/FileValidator.h>
63#include <IPXACTmodels/Design/Interconnection.h>
64#include <IPXACTmodels/Design/AdHocConnection.h>
65#include <IPXACTmodels/Design/ActiveInterface.h>
66#include <IPXACTmodels/Design/Design.h>
69#include <IPXACTmodels/DesignConfiguration/DesignConfiguration.h>
76 constructMemoryValidators();
77 constructMemoryInterface();
78 constructFileSetInterface();
86 library_->searchForIPXactFiles();
94 return KactusAPI::getVersion().toStdString();
102 QStringList locations = KactusAPI::getAllLibraryPaths();
104 std::vector<std::string> paths;
105 for (
auto const& path : locations)
107 paths.push_back(path.toStdString());
118 KactusAPI::setLibraryPathActive(QString::fromStdString(path), isActive);
126 KactusAPI::addLibraryPath(QString::fromStdString(path), isActive);
134 if (KactusAPI::removeLibraryPath(QString::fromStdString(path)) ==
false)
136 messager_->showError(QStringLiteral(
"Error: Cannot remove default library path"));
145 QStringList locations = KactusAPI::getActiveLibraryPaths();
147 std::vector<std::string> paths;
148 for (
auto const& path : locations)
150 paths.push_back(path.toStdString());
161 return portsInterface_;
169 return componentParameterInterface_;
177 return mapInterface_;
185 return fileSetInterface_;
193 return busInterface_;
201 QStringList libraryPaths;
202 for (
auto const& path : paths)
204 libraryPaths.append(QString::fromStdString(path));
207 KactusAPI::setLibraryPaths(libraryPaths);
215 return KactusAPI::getDefaultLibraryPath().toStdString();
223 KactusAPI::setDefaultLibraryPath(QString::fromStdString(path));
231 VLNV targetVLNV(VLNV::COMPONENT, QString::fromStdString(vlnv));
233 return KactusAPI::importFile(QString::fromStdString(path), targetVLNV, overwrite);
240 std::string
const& outputDirectory)
const
242 VLNV componentVLNV(VLNV::COMPONENT, QString::fromStdString(vlnv));
243 KactusAttribute::Implementation implementation = KactusAttribute::HW;
245 QString fileFormat = QString::fromStdString(format).toLower();
247 QStringList availableFormats;
250 for (
auto plugin : KactusAPI::getPlugins())
264 if (generator !=
nullptr)
266 KactusAPI::runGenerator(generator, componentVLNV, QString::fromStdString(viewName),
267 QString::fromStdString(outputDirectory), implementation,
nullptr);
271 availableFormats.sort(Qt::CaseInsensitive);
272 messager_->showError(QStringLiteral(
"No generator found for format %1. Available options are: %2").arg(
273 fileFormat, availableFormats.join(
',')));
285 VLNV interconVLNV = interconGen.generate();
293 return library_->getAllVLNVs().count();
301 std::vector<std::string> vlnvStrings;
303 for (
auto const& itemVLNV : library_->getAllVLNVs())
305 vlnvStrings.push_back(itemVLNV.toString().toStdString());
316 std::vector<std::string> componentVLNVs;
318 for (
auto const& itemVLNV : library_->getAllVLNVs())
320 if (itemVLNV.getType() == VLNV::COMPONENT)
322 componentVLNVs.push_back(itemVLNV.toString().toStdString());
326 return componentVLNVs;
333 std::string
const& version)
const
335 if (vendor.empty() || library.empty() || name.empty() || version.empty())
337 messager_->showError(
"Error in given VLNV.");
341 return library_->contains(VLNV(VLNV::INVALID,
342 QString::fromStdString(vendor),
343 QString::fromStdString(library),
344 QString::fromStdString(name),
345 QString::fromStdString(version)));
352 std::string
const& version,
StdRev revision )
354 if (vendor.empty() || library.empty() || name.empty() || version.empty())
356 messager_->showError(
"Error in given VLNV.");
360 VLNV newComponentVLNV;
361 newComponentVLNV.setVendor(QString::fromStdString(vendor));
362 newComponentVLNV.setLibrary(QString::fromStdString(library));
363 newComponentVLNV.setName(QString::fromStdString(name));
364 newComponentVLNV.setVersion(QString::fromStdString(version));
365 newComponentVLNV.setType(VLNV::COMPONENT);
367 if (library_->contains(newComponentVLNV))
373 ? Document::Revision::Std22 : Document::Revision::Std14;
375 QSharedPointer<Component> component = QSharedPointer<Component>(
new Component(newComponentVLNV, docRevision));
377 component->setHierarchy(KactusAttribute::FLAT);
378 component->setFirmness(KactusAttribute::MUTABLE);
379 component->setImplementation(KactusAttribute::HW);
380 component->setVersion(KactusAPI::getVersionFileString());
382 QString directory = KactusAPI::getDefaultLibraryPath();
383 QString vlnvDir =
"/" + newComponentVLNV.getVendor() +
"/" + newComponentVLNV.getLibrary() +
"/" +
384 newComponentVLNV.getName() +
"/" + newComponentVLNV.getVersion();
386 directory += vlnvDir;
388 if (!library_->writeModelToFile(directory, component))
390 messager_->showError(
"Error saving file to disk.");
403 std::string
const& name, std::string
const& version)
const
406 documentVLNV.setVendor(QString::fromStdString(vendor));
407 documentVLNV.setLibrary(QString::fromStdString(library));
408 documentVLNV.setName(QString::fromStdString(name));
409 documentVLNV.setVersion(QString::fromStdString(version));
411 return KactusAPI::getDocumentFilePath(documentVLNV).toStdString();
419 if (activeComponent_)
421 QStringList componentNames = activeComponent_->getViewNames();
422 if (!componentNames.isEmpty())
424 return componentNames.first().toStdString();
428 QSharedPointer<View> newView(
new View(
"mockView"));
429 activeComponent_->getViews()->append(newView);
430 return newView->name().toStdString();
434 return std::string();
442 QString componentVLNV = QString::fromStdString(vlnvString);
443 QSharedPointer<Document> componentDocument = getDocument(componentVLNV);
444 if (componentDocument)
446 QSharedPointer<Component> component = componentDocument.dynamicCast<Component>();
449 parameterFinder_->setComponent(component);
450 portValidator_->componentChange(component->getViews());
451 portsInterface_->setPorts(component->getPorts());
453 parameterValidator_->componentChange(component->getChoices(), component->getRevision());
454 componentParameterInterface_->setParameters(component->getParameters());
455 componentParameterInterface_->setChoices(component->getChoices());
457 mapValidator_->componentChange(component);
458 mapInterface_->setMemoryMaps(component);
460 fileSetInterface_->setFileSets(component->getFileSets());
462 busInterface_->setBusInterfaces(component);
464 activeComponent_ = component;
465 messager_->showMessage(QString(
"Component %1 is open").arg(componentVLNV));
470 messager_->showError(QString(
"The given VLNV %1 is not a component").arg(componentVLNV));
476 messager_->showError(QString(
"Could not open document with VLNV %1").arg(componentVLNV));
484QSharedPointer<Document> PythonAPI::getDocument(QString
const& vlnvString)
const
486 QStringList vlnvArray = vlnvString.split(
':');
487 if (vlnvArray.size() != 4)
489 messager_->
showError(QString(
"The given VLNV %1 is not valid").arg(vlnvString));
490 return QSharedPointer<Document>();
493 VLNV targetVLNV(VLNV::COMPONENT, vlnvArray.at(0), vlnvArray.at(1), vlnvArray.at(2), vlnvArray.at(3));
494 return library_->getModel(targetVLNV);
502 if (activeComponent_)
504 messager_->showMessage(QString(
"Component %1 is closed").arg(activeComponent_->getVlnv().toString()));
507 activeComponent_ = QSharedPointer<Component>();
515 if (activeComponent_)
517 return activeComponent_->getVlnv().getName().toStdString();
521 return std::string();
530 if (activeComponent_)
532 return activeComponent_->getDescription().toStdString();
536 return std::string();
545 if (activeComponent_)
547 return Document::toStdString(activeComponent_->getRevision());
550 return std::string();
558 if (activeComponent_)
560 messager_->showMessage(QString(
"Saving component %1 ...").arg(activeComponent_->getVlnv().toString()));
563 if (library_->writeModelToFile(activeComponent_))
565 messager_->showMessage(QString(
"Save complete"));
569 messager_->showError(QString(
"Could not save component %1").arg(activeComponent_->getVlnv().toString()));
578void PythonAPI::constructMemoryValidators()
580 QSharedPointer<EnumeratedValueValidator> enumValidator(
new EnumeratedValueValidator(expressionParser_));
581 QSharedPointer<FieldValidator>fieldValidator(
new FieldValidator(
582 expressionParser_, enumValidator, parameterValidator_));
583 QSharedPointer<RegisterValidator> registerValidator (
new RegisterValidator(
584 expressionParser_, fieldValidator, parameterValidator_));
585 QSharedPointer<RegisterFileValidator> registerFileValidator(
586 new RegisterFileValidator(expressionParser_, registerValidator, parameterValidator_,
587 Document::Revision::Unknown));
589 QSharedPointer<AddressBlockValidator> blockValidator(
new AddressBlockValidator(
590 expressionParser_, registerValidator, registerFileValidator, parameterValidator_,
591 Document::Revision::Unknown));
593 QSharedPointer<SubspaceMapValidator> subspaceValidator(
594 new SubspaceMapValidator(expressionParser_, parameterValidator_, Document::Revision::Unknown));
596 QSharedPointer<MemoryMapValidator> mapValidator(
597 new MemoryMapValidator(expressionParser_, blockValidator, subspaceValidator, QSharedPointer<Component>()));
599 mapValidator_ = mapValidator;
605void PythonAPI::constructMemoryInterface()
607 QSharedPointer<SubspaceMapValidator> subspaceValidator = mapValidator_->getSubspaceValidator();
608 QSharedPointer<AddressBlockValidator> blockValidator = mapValidator_->getAddressBlockValidator();
609 QSharedPointer<RegisterValidator> registerValidator = blockValidator->getRegisterValidator();
610 QSharedPointer<FieldValidator> fieldValidator = registerValidator->getFieldValidator();
612 ResetInterface* resetInterface(
new ResetInterface(fieldValidator, expressionParser_, expressionFormatter_));
613 FieldInterface* fieldInterface(
614 new FieldInterface(fieldValidator, expressionParser_, expressionFormatter_, resetInterface));
616 ModeReferenceInterface* modeReferenceInterface(
new ModeReferenceInterface());
618 AccessPolicyInterface* accessPolicyInterface(
new AccessPolicyInterface(modeReferenceInterface));
620 RegisterInterface* registerInterface(
621 new RegisterInterface(registerValidator, expressionParser_, expressionFormatter_, fieldInterface,
622 accessPolicyInterface));
624 AddressBlockInterface* blockInterface(
new AddressBlockInterface(blockValidator, expressionParser_,
625 expressionFormatter_, busInterface_, registerInterface, componentParameterInterface_));
626 SubspaceMapInterface* subspaceInterface(
new SubspaceMapInterface(
627 subspaceValidator, expressionParser_, expressionFormatter_, busInterface_, componentParameterInterface_));
629 mapInterface_ =
new MemoryMapInterface(mapValidator_, expressionParser_, expressionFormatter_);
631 mapInterface_->setAddressBlockInterface(blockInterface);
632 mapInterface_->setSubspaceMapInterface(subspaceInterface);
633 mapInterface_->setModeReferenceInterface(modeReferenceInterface);
643 QString mapNameQT = QString::fromStdString(mapName);
644 QSharedPointer<MemoryMap> containingMap = getMemoryMap(mapNameQT);
647 sendMemoryMapNotFoundError(mapNameQT);
652 blockInterface->
setAddressUnitBits(containingMap->getAddressUnitBits().toStdString());
662 QString mapNameQT = QString::fromStdString(mapName);
663 QString blockNameQT = QString::fromStdString(blockName);
665 QSharedPointer<MemoryMap> containingMap = getMemoryMap(mapNameQT);
668 QSharedPointer<AddressBlock> containingBlock = getAddressBock(containingMap, blockNameQT);
671 interfacePointer->
setRegisters(containingBlock->getRegisterData());
673 expressionParser_->parseExpression(containingMap->getAddressUnitBits()).toInt());
677 sendAddressBlockNotFoundError(mapNameQT, blockNameQT);
682 sendMemoryMapNotFoundError(mapNameQT);
690 std::string
const& registerName)
693 mapInterface_->getAddressBlockInterface()->
getSubInterface()->getSubInterface();
695 QString mapNameQT = QString::fromStdString(mapName);
696 QString blockNameQT = QString::fromStdString(blockName);
697 QString registerNameQT = QString::fromStdString(registerName);
699 QSharedPointer<MemoryMap> containingMap = getMemoryMap(mapNameQT);
702 QSharedPointer<AddressBlock> containingBlock = getAddressBock(containingMap, blockNameQT);
705 QSharedPointer<Register> containingRegister = getRegister(containingBlock, registerNameQT);
706 if (containingRegister)
708 interfacePointer->
setFields(containingRegister->getFields());
712 sendRegisterNotFoundError(mapNameQT, blockNameQT, registerNameQT);
717 sendAddressBlockNotFoundError(mapNameQT, blockNameQT);
722 sendMemoryMapNotFoundError(mapNameQT);
730 std::string
const& registerName, std::string
const& fieldName)
733 mapInterface_->getAddressBlockInterface()->getSubInterface()->getSubInterface()->getSubInterface();
735 QString mapNameQT = QString::fromStdString(mapName);
736 QString blockNameQT = QString::fromStdString(blockName);
737 QString registerNameQT = QString::fromStdString(registerName);
738 QString fieldNameQT = QString::fromStdString(fieldName);
740 QSharedPointer<MemoryMap> containingMap = getMemoryMap(mapNameQT);
743 QSharedPointer<AddressBlock> containingBlock = getAddressBock(containingMap, blockNameQT);
746 QSharedPointer<Register> containingRegister = getRegister(containingBlock, registerNameQT);
747 if (containingRegister)
749 QSharedPointer<Field> containingField = getField(containingRegister, fieldNameQT);
752 interfacePointer->
setResets(containingField);
756 sendFieldNotFoundError(mapNameQT, blockNameQT, registerNameQT, fieldNameQT);
761 sendRegisterNotFoundError(mapNameQT, blockNameQT, registerNameQT);
766 sendAddressBlockNotFoundError(mapNameQT, blockNameQT);
771 sendMemoryMapNotFoundError(mapNameQT);
778QSharedPointer<MemoryMap> PythonAPI::getMemoryMap(QString
const& mapName)
const
780 for (
auto map : *activeComponent_->getMemoryMaps())
782 if (map->name() == mapName)
788 return QSharedPointer<MemoryMap>();
794QSharedPointer<AddressBlock> PythonAPI::getAddressBock(QSharedPointer<MemoryMap> containingMap,
795 QString
const& blockName)
const
797 for (
auto baseBlock : *containingMap->getMemoryBlocks())
799 QSharedPointer<AddressBlock> block = baseBlock.dynamicCast<AddressBlock>();
800 if (block && block->name() == blockName)
806 return QSharedPointer<AddressBlock>();
812QSharedPointer<Register> PythonAPI::getRegister(QSharedPointer<AddressBlock> containingBlock,
813 QString
const& registerName)
const
815 for (
auto baseRegister : *containingBlock->getRegisterData())
817 QSharedPointer<Register> currentRegister = baseRegister.dynamicCast<Register>();
818 if (currentRegister && currentRegister->name() == registerName)
820 return currentRegister;
824 return QSharedPointer<Register>();
830QSharedPointer<Field> PythonAPI::getField(QSharedPointer<Register> containingRegister, QString
const& fieldName)
833 for (
auto currentField : *containingRegister->getFields())
835 if (currentField->name() == fieldName)
841 return QSharedPointer<Field>();
847void PythonAPI::constructFileSetInterface()
849 QSharedPointer<FileValidator> newFileValidator(
new FileValidator(expressionParser_));
850 QSharedPointer<FileSetValidator> newFileSetValidator(
851 new FileSetValidator(newFileValidator, expressionParser_));
853 FileInterface* fileInterface =
new FileInterface(newFileValidator, expressionParser_, expressionFormatter_);
855 FileBuilderInterface* fileBuilderInterface =
new FileBuilderInterface(expressionParser_, expressionFormatter_);
857 fileSetInterface_ =
new FileSetInterface(
858 newFileSetValidator, expressionParser_, expressionFormatter_, fileInterface, fileBuilderInterface);
866 FileInterface* fileInterface = fileSetInterface_->getFileInterface();
868 QString fileSetNameQT = QString::fromStdString(setName);
869 QSharedPointer<FileSet> containingFileSet = getFileSet(fileSetNameQT);
870 if (!containingFileSet)
872 sendFileSetNotFoundError(fileSetNameQT);
876 fileInterface->
setFiles(containingFileSet->getFiles());
882QSharedPointer<FileSet> PythonAPI::getFileSet(QString
const& setName)
const
884 for (
auto fileSet : *activeComponent_->getFileSets())
886 if (fileSet->name() == setName)
892 return QSharedPointer<FileSet>();
902 QString fileSetNameQT = QString::fromStdString(setName);
903 QSharedPointer<FileSet> containingFileSet = getFileSet(fileSetNameQT);
904 if (!containingFileSet)
906 sendFileSetNotFoundError(fileSetNameQT);
910 builderInterface->
setFileBuilders(containingFileSet->getDefaultFileBuilders());
917 std::string
const& name, std::string
const& version,
StdRev revision )
919 if (vendor.empty() || library.empty() || name.empty() || version.empty())
921 messager_->showError(
"Error in given VLNV.");
925 VLNV componentVLNV(VLNV::DESIGN,
926 QString::fromStdString(vendor),
927 QString::fromStdString(library),
928 QString::fromStdString(name),
929 QString::fromStdString(version));
931 if (
createComponent(vendor, library, name, version, revision) ==
false)
933 messager_->showError(
"Error in creating containing component.");
937 VLNV designVLNV(VLNV::DESIGN, componentVLNV.getVendor(), componentVLNV.getLibrary(),
938 componentVLNV.getName() +
".design", componentVLNV.getVersion());
939 VLNV desConfVLNV(VLNV::DESIGNCONFIGURATION, componentVLNV.getVendor(), componentVLNV.getLibrary(),
940 componentVLNV.getName()+
".designcfg", componentVLNV.getVersion());
942 if (library_->contains(designVLNV))
947 QSharedPointer<DesignConfigurationInstantiation> hierarchicalInstantiation
948 (
new DesignConfigurationInstantiation(desConfVLNV.getName() +
"_" + desConfVLNV.getVersion()));
950 QSharedPointer<ConfigurableVLNVReference> tempReference(
new ConfigurableVLNVReference(desConfVLNV));
951 hierarchicalInstantiation->setDesignConfigurationReference(tempReference);
953 QSharedPointer<View> newHierarchicalView(
new View(QStringLiteral(
"hierarchical")));
954 newHierarchicalView->setDesignConfigurationInstantiationRef(hierarchicalInstantiation->name());
956 activeComponent_->getDesignConfigurationInstantiations()->append(hierarchicalInstantiation);
957 activeComponent_->getViews()->append(newHierarchicalView);
959 auto design = QSharedPointer<Design>(
new Design(designVLNV, Document::Revision::Std14));
960 design->setVersion(KactusAPI::getVersionFileString());
961 design->setDesignImplementation(KactusAttribute::HW);
964 auto designConf = QSharedPointer<DesignConfiguration>(
new DesignConfiguration(desConfVLNV, Document::Revision::Std14));
965 designConf->setDesignRef(designVLNV);
966 designConf->setDesignConfigImplementation(KactusAttribute::HW);
967 designConf->setVersion(KactusAPI::getVersionFileString());
969 if (QString directory = KactusAPI::getDefaultLibraryPath() +
"/" + designVLNV.toString(QStringLiteral(
"/"));
970 !library_->writeModelToFile(activeComponent_) ||
971 !library_->writeModelToFile(directory, design) ||
972 !library_->writeModelToFile(directory, designConf))
974 messager_->showError(
"Error saving file to disk.");
978 openDesign(designVLNV.toString().toStdString());
990 return Document::toStdString(activeDesign_->getRevision());
993 return std::string();
999void PythonAPI::sendMemoryMapNotFoundError(QString
const& mapName)
const
1001 messager_->
showError(QString(
"Could not find memory map %1 within component %2").
1002 arg(mapName, activeComponent_->getVlnv().toString()));
1008void PythonAPI::sendAddressBlockNotFoundError(QString
const& mapName, QString
const& blockName)
const
1010 messager_->showError(QString(
"Could not find address block %1 within memory map %2 in component %3").
1011 arg(blockName, mapName, activeComponent_->getVlnv().toString()));
1017void PythonAPI::sendRegisterNotFoundError(QString
const& mapName, QString
const& blockName,
1018 QString
const& registerName)
const
1020 messager_->showError(
1021 QString(
"Could not find register %1 within address block %2 in memory map %3 in component %4").
1022 arg(registerName, blockName, mapName, activeComponent_->getVlnv().toString()));
1028void PythonAPI::sendFieldNotFoundError(QString
const& mapName, QString
const& blockName,
1029 QString
const& registerName, QString
const& fieldName)
const
1031 messager_->showError(
1032 QString(
"Could not find field %1 within register %2 in address block %3 in memory map %4 in component %5").
1033 arg(fieldName, registerName, blockName, mapName, activeComponent_->getVlnv().toString()));
1039void PythonAPI::sendFileSetNotFoundError(QString
const& setName)
const
1041 messager_->showError(QString(
"Could not find file set %1 within component %2").
1042 arg(setName, activeComponent_->getVlnv().toString()));
1050 QString designVLNV = QString::fromStdString(vlnvString);
1051 QSharedPointer<Document> designDocument = getDocument(designVLNV);
1054 QSharedPointer<Design> design = designDocument.dynamicCast<Design>();
1057 activeDesign_ = design;
1058 messager_->showMessage(QString(
"Design %1 is open").arg(designVLNV));
1060 instanceInterface_->setComponentInstances(activeDesign_);
1061 connectionInterface_->setInterconnections(activeDesign_);
1062 adhocConnectionInterface_->setConnections(activeDesign_);
1068 messager_->showError(QString(
"The given VLNV %1 is not a design").arg(designVLNV));
1074 messager_->showError(QString(
"Could not open document with VLNV %1").arg(designVLNV));
1086 messager_->showMessage(QString(
"Design %1 is closed").arg(activeDesign_->getVlnv().toString()));
1089 activeDesign_ = QSharedPointer<Design>();
1099 messager_->showMessage(QString(
"Saving design %1 ...").arg(activeDesign_->getVlnv().toString()));
1101 if (library_->writeModelToFile(activeDesign_))
1103 messager_->showMessage(QString(
"Save complete"));
1107 messager_->showError(QString(
"Could not save design %1").arg(activeDesign_->getVlnv().toString()));
1119 messager_->showMessage(QString(
"No open design"));
1123 QString combinedVLNV = QString::fromStdString(vlnvString);
1124 QSharedPointer<Document> instanceDocument = getDocument(combinedVLNV);
1125 if (!instanceDocument)
1127 messager_->showMessage(QString(
"Could not find document %1").arg(combinedVLNV));
1131 QSharedPointer<Component> instanceComponent = instanceDocument.dynamicCast<Component>();
1132 if (!instanceComponent)
1134 messager_->showMessage(QString(
"%1 is not a component").arg(combinedVLNV));
1138 QStringList vlnvList = combinedVLNV.split(
":");
1139 if (vlnvList.size() < 4)
1141 messager_->showMessage(QString(
"The VLNV %1 is not correct").arg(combinedVLNV));
1145 std::string newVendor = vlnvList.at(0).toStdString();
1146 std::string newLibrary = vlnvList.at(1).toStdString();
1147 std::string newName = vlnvList.at(2).toStdString();
1148 std::string newVersion = vlnvList.at(3).toStdString();
1150 instanceInterface_->addComponentInstance(instanceName);
1151 return instanceInterface_->setComponentReference(instanceName, newVendor, newLibrary, newName, newVersion);
1161 messager_->showMessage(QString(
"No open design"));
1165 return instanceInterface_->removeComponentInstance(instanceName);
1173 return connectionInterface_->removeInstanceInterconnections(instanceName);
1181 return adhocConnectionInterface_->removeInstanceAdHocConnections(instanceName);
1189 return instanceInterface_->setName(currentName, newName);
1196 std::string
const& endInstanceName, std::string
const& endBus)
1198 QString startInstanceNameQ = QString::fromStdString(startInstanceName);
1199 QString endInstanceNameQ = QString::fromStdString(endInstanceName);
1200 QString startBusNameQ = QString::fromStdString(startBus);
1201 QString endBusNameQ = QString::fromStdString(endBus);
1203 if (!connectionEndsCheck(startInstanceNameQ, startBusNameQ, endInstanceNameQ, endBusNameQ,
false))
1205 messager_->showMessage(QString(
"Could not create connection"));
1209 connectionInterface_->addInterconnection(startInstanceName, startBus, endInstanceName, endBus);
1218 std::string
const& topBus)
1220 QString instanceNameQ = QString::fromStdString(instanceName);
1221 QString instanceBusNameQ = QString::fromStdString(instanceBus);
1222 QString topBusQ = QString::fromStdString(topBus);
1224 if (!instanceExists(instanceNameQ))
1226 messager_->showMessage(QString(
"Could not create connection"));
1230 connectionInterface_->addHierarchicalInterconnection(instanceName, instanceBus, topBus);
1238bool PythonAPI::connectionEndsCheck(QString
const& startInstanceName, QString
const& startBus,
1239 QString
const& endInstanceName, QString
const& endBus,
bool isAdHocConnection)
1241 if (instanceExists(startInstanceName) ==
false || instanceExists(endInstanceName) ==
false)
1246 QSharedPointer<ConfigurableVLNVReference> startComponenReference =
1247 instanceInterface_->getComponentReference(startInstanceName.toStdString());
1248 QSharedPointer<ConfigurableVLNVReference> endComponentReference =
1249 instanceInterface_->getComponentReference(endInstanceName.toStdString());
1250 QSharedPointer<const Document> startDocument = library_->getModelReadOnly(*startComponenReference.data());
1251 QSharedPointer<const Document> endDocument = library_->getModelReadOnly(*endComponentReference.data());
1252 QSharedPointer<const Component> startComponent = startDocument.dynamicCast<
const Component>();
1253 QSharedPointer<const Component> endComponent = endDocument.dynamicCast<
const Component>();
1256 if (isAdHocConnection)
1258 return endsCheckForAdHoc(
1259 startComponent, startBus, startInstanceName, endComponent, endBus, endInstanceName);
1263 return endsCheckForInterconnection(
1264 startComponent, startBus, startInstanceName, endComponent, endBus, endInstanceName);
1271bool PythonAPI::instanceExists(QString
const& instanceName)
const
1273 if (!instanceInterface_->instanceExists(instanceName.toStdString()))
1275 messager_->showMessage(QString(
"Could not find component instance %1 within %2").
1276 arg(instanceName, activeDesign_->getVlnv().toString()));
1280 QSharedPointer<ConfigurableVLNVReference> instanceComponenReference =
1281 instanceInterface_->getComponentReference(instanceName.toStdString());
1283 if (!instanceComponenReference)
1285 messager_->showMessage(QString(
"Component instance %1 does not have a component reference").
1290 QSharedPointer<const Document> instanceDocument =
1291 library_->getModelReadOnly(*instanceComponenReference.data());
1292 if (!instanceDocument)
1294 messager_->showMessage(QString(
"Component instance %1 references a non-existing document %2").
1295 arg(instanceName, instanceComponenReference->toString()));
1299 QSharedPointer<const Component> instanceComponent = instanceDocument.dynamicCast<
const Component>();
1300 if (!instanceComponent)
1302 messager_->showMessage(QString(
"Component instance %1 component reference %1 is not a component").
1303 arg(instanceName, instanceComponenReference->toString()));
1313bool PythonAPI::endsCheckForAdHoc(QSharedPointer<const Component> startComponent, QString
const& startBus,
1314 QString
const& startInstanceName, QSharedPointer<const Component> endComponent, QString
const& endBus,
1315 QString
const& endInstanceName)
1317 openComponent(startComponent->getVlnv().toString().toStdString());
1319 DirectionTypes::Direction startDirection =
1320 DirectionTypes::str2Direction(QString::fromStdString(portsInterface_->getDirection(
1321 startBus.toStdString())), DirectionTypes::DIRECTION_INVALID);
1323 if (!portsInterface_->portExists(startBus.toStdString()))
1325 messager_->showMessage(QString(
"Could not find port %1 within component instance %2.").
1326 arg(startBus, startInstanceName));
1330 openComponent(endComponent->getVlnv().toString().toStdString());
1331 DirectionTypes::Direction endDirection = DirectionTypes::str2Direction(QString::fromStdString(
1332 portsInterface_->getDirection(endBus.toStdString())), DirectionTypes::DIRECTION_INVALID);
1334 if (!portsInterface_->portExists(endBus.toStdString()))
1336 messager_->showMessage(QString(
"Could not find port %1 within component instance %2.").
1337 arg(endBus, endInstanceName));
1343 if (startDirection == DirectionTypes::DIRECTION_INVALID ||
1344 endDirection == DirectionTypes::DIRECTION_INVALID ||
1345 (startDirection == DirectionTypes::IN && endDirection == DirectionTypes::IN) ||
1346 (startDirection == DirectionTypes::OUT && endDirection == DirectionTypes::OUT))
1348 messager_->showMessage(QString(
"Ports %1 in %2 and %3 in %4 have incompatible directions %5 and %6.").
1349 arg(startBus, startInstanceName, endBus, endInstanceName,
1350 DirectionTypes::direction2Str(startDirection), DirectionTypes::direction2Str(endDirection)));
1360bool PythonAPI::endsCheckForInterconnection(QSharedPointer<const Component> startComponent,
1361 QString
const& startBus, QString
const& startInstanceName, QSharedPointer<const Component> endComponent,
1362 QString
const& endBus, QString
const& endInstanceName)
1364 openComponent(startComponent->getVlnv().toString().toStdString());
1366 ConfigurableVLNVReference startBusType = busInterface_->getBusType(startBus.toStdString());
1367 General::InterfaceMode startMode = busInterface_->getMode(startBus.toStdString());
1368 General::InterfaceMode startMonitor = busInterface_->getMonitorMode(startBus.toStdString());
1370 if (!busInterface_->busInterfaceExists(startBus.toStdString()))
1372 messager_->showMessage(QString(
"Could not find bus interface %1 within component instance %2.").
1373 arg(startBus, startInstanceName));
1377 openComponent(endComponent->getVlnv().toString().toStdString());
1379 ConfigurableVLNVReference endBusType = busInterface_->getBusType(endBus.toStdString());
1380 General::InterfaceMode endMode = busInterface_->getMode(endBus.toStdString());
1381 General::InterfaceMode endMonitor = busInterface_->getMonitorMode(endBus.toStdString());
1383 if (!busInterface_->busInterfaceExists(endBus.toStdString()))
1385 messager_->showMessage(QString(
"Could not find bus interface %1 within component instance %2.").
1386 arg(endBus, endInstanceName));
1394 messager_->showMessage(QString(
"Bus interfaces %1 in %2 and %3 in %4 are not of the same bus type").
1395 arg(startBus, startInstanceName, endBus, endInstanceName));
1399 QVector<General::InterfaceMode> startCompatibleModes =
1400 General::getCompatibleInterfaceModesForActiveInterface(startMode);
1402 if ((startMode == General::MONITOR && startMonitor != endMode) ||
1403 (endMode == General::MONITOR && endMonitor != startMode) ||
1404 !startCompatibleModes.contains(endMode))
1406 QString startModeString = General::interfaceMode2Str(startMode);
1407 QString endModeString = General::interfaceMode2Str(endMode);
1408 if (startMode == General::MONITOR)
1410 startModeString = General::interfaceMode2Str(startMonitor);
1412 if (endMode == General::MONITOR)
1414 endModeString = General::interfaceMode2Str(endMonitor);
1417 messager_->showMessage(QString(
1418 "Bus interface modes of %1 in %2 and %3 in %4 have incompatible bus interface modes %5 and %6.").
1419 arg(startBus, startInstanceName, endBus, endInstanceName, startModeString, endModeString));
1430 std::string
const& endInstanceName, std::string
const& endBus)
1432 std::string connectionName =
1433 connectionInterface_->getConnectionName(startInstanceName, startBus, endInstanceName, endBus);
1435 return removeConnection(connectionName);
1442 std::string
const& topBus)
1444 std::string connectionName =
1445 connectionInterface_->getHierarchicalConnectionName(instanceName, instanceBus, topBus);
1447 return removeConnection(connectionName);
1453bool PythonAPI::removeConnection(std::string
const& connectionName)
1457 if (success ==
false)
1459 messager_->
showMessage(QString(
"Could not find connection %1.").
1460 arg(QString::fromStdString(connectionName)));
1471 return connectionInterface_->setName(currentName, newName);
1478 std::string
const& endInstanceName, std::string
const& endPort)
1480 QString startInstanceNameQ = QString::fromStdString(startInstanceName);
1481 QString endInstanceNameQ = QString::fromStdString(endInstanceName);
1482 QString startPortNameQ = QString::fromStdString(startPort);
1483 QString endPortNameQ = QString::fromStdString(endPort);
1485 if (!connectionEndsCheck(startInstanceNameQ, startPortNameQ, endInstanceNameQ, endPortNameQ,
true))
1487 messager_->showMessage(QString(
"Could not create connection"));
1491 adhocConnectionInterface_->addAdHocConnection(startInstanceName, startPort, endInstanceName, endPort);
1500 std::string
const& topPort)
1502 QString instanceNameQ = QString::fromStdString(instanceName);
1503 QString instancePortQ = QString::fromStdString(instancePort);
1504 QString topPortQ = QString::fromStdString(topPort);
1506 if (!instanceExists(instanceNameQ))
1508 messager_->showMessage(QString(
"Could not create connection"));
1512 adhocConnectionInterface_->addHierarchicalAdHocConnection(instanceName, instancePort, topPort);
1520 std::string
const& endInstanceName, std::string
const& endPort)
1522 std::string connectionName =
1523 adhocConnectionInterface_->getConnectionName(startInstanceName, startPort, endInstanceName, endPort);
1525 return removeAdHocConnection(connectionName);
1531bool PythonAPI::removeAdHocConnection(std::string
const& connectionName)
1534 if (success ==
false)
1536 messager_->
showMessage(QString(
"Could not find connection %1.").
1537 arg(QString::fromStdString(connectionName)));
1547 std::string
const& topPort)
1549 std::string connectionName =
1550 adhocConnectionInterface_->getHierarchicalConnectionName(instanceName, instancePort, topPort);
1552 return removeAdHocConnection(connectionName);
1560 return adhocConnectionInterface_->setName(currentName, newName);
bool removeAdHocConnection(std::string const &connectionName)
Interface for editing address blocks.
Interface for accessing bus interfaces.
Interface for enabling plugin run using the command line arguments.
virtual QString getOutputFormat() const =0
Interface for editing fields.
ResetInterface * getSubInterface() const
void setFields(QSharedPointer< QList< QSharedPointer< Field > > > newFields)
Interface for editing file builders.
void setFileBuilders(QSharedPointer< QList< QSharedPointer< FileBuilder > > > newFileBuilders)
Interface for editing files.
void setFiles(QSharedPointer< QList< QSharedPointer< File > > > newFiles)
Interface for editing filesets.
Generator plugins can be used in the component editor and design editors to generate content for the ...
bool removeInterconnection(std::string const &connectionName)
void setAddressUnitBits(std::string const &newAddressUnitbits)
void setMemoryBlocks(QSharedPointer< QList< QSharedPointer< MemoryBlockBase > > > newMemoryBlocks)
Interface for editing memory maps and remaps.
Interface for editing parameters.
Interface for editing component ports.
std::string getVersion() const
bool removeInstanceConnections(std::string const &instanceName)
void setupLibrary(std::string const &settingsFileString)
bool renameAdHocConnection(std::string const ¤tName, std::string const &newName)
bool removeComponentInstance(std::string const &instanceName)
bool removeHierarchicalConnection(std::string const &instanceName, std::string const &instanceBus, std::string const &topBus)
void removeLibraryPath(std::string const &path)
bool renameInstance(std::string const ¤tName, std::string const &newName)
std::string getFirstViewName() const
bool openComponent(std::string const &vlnvString)
std::string getComponentDescription() const
void setLibraryPathActive(std::string const &path, bool isActive)
BusInterfaceInterface * getBusInterface()
void setRegistersForInterface(std::string const &mapName, std::string const &blockName)
std::vector< std::string > getActiveLibraryPaths() const
PortsInterface * getPortsInterface() const
std::vector< std::string > listVLNVs(std::string const &vendor=std::string()) const
void setFieldsForInterface(std::string const &mapName, std::string const &blockName, std::string const ®isterName)
ParametersInterface * getComponentParameterInterface() const
bool createComponent(std::string const &vendor, std::string const &library, std::string const &name, std::string const &version, StdRev revision=StdRev::Std22)
void setBlocksForInterface(std::string const &mapName)
FileSetInterface * getFileSetInterface()
void setDefaultLibraryPath(std::string const &path) const
void generateInterconnect()
std::vector< std::string > listComponentVLNVs() const
void generate(std::string const &format, std::string const &vlnv, std::string const &viewName, std::string const &outputDirectory) const
void setFilesForInterface(std::string const &setName)
std::string getDesignStdRevision() const
void setResetsForInterface(std::string const &mapName, std::string const &blockName, std::string const ®isterName, std::string const &fieldName)
bool removeHierarchicalAdHocConnection(std::string const &instanceName, std::string const &instancePort, std::string const &topPort)
bool createConnection(std::string const &startInstanceName, std::string const &startBus, std::string const &endInstanceName, std::string const &endBus)
bool removeInstanceAdHocConnections(std::string const &instanceName)
std::string getComponentStdRevision() const
void setLibraryPaths(std::vector< std::string > const &paths) const
bool removeInstanceAdHocConnection(std::string const &startInstanceName, std::string const &startPort, std::string const &endInstanceName, std::string const &endPort)
int importFile(std::string const &path, std::string const &vlnv, bool overwrite=false) const
bool removeInstanceConnection(std::string const &startInstanceName, std::string const &startBus, std::string const &endInstanceName, std::string const &endBus)
bool createHierarchicalAdHocConnection(std::string const &instanceName, std::string const &instancePort, std::string const &topPort)
void addLibraryPath(std::string const &path, bool isActive=true)
bool addComponentInstance(std::string const &vlnvString, std::string const &instanceName)
void closeOpenComponent()
bool createAdHocConnection(std::string const &startInstanceName, std::string const &startPort, std::string const &endInstanceName, std::string const &endPort)
std::vector< std::string > getAllLibraryPaths() const
std::string getVLNVDirectory(std::string const &vendor, std::string const &library, std::string const &name, std::string const &version) const
bool vlnvExistsInLibrary(std::string const &vendor, std::string const &library, std::string const &name, std::string const &version) const
bool createHierarchicalConnection(std::string const &instanceName, std::string const &instanceBus, std::string const &topBus)
bool createDesign(std::string const &vendor, std::string const &library, std::string const &name, std::string const &version, StdRev revision=StdRev::Std22)
std::string getDefaultLibraryPath() const
std::string getComponentName() const
void setFileBuildersForInterface(std::string const &setName)
bool renameConnection(std::string const ¤tName, std::string const &newName)
MemoryMapInterface * getMapInterface()
bool openDesign(std::string const &vlnvString)
Interface for editing registers.
void setRegisters(QSharedPointer< QList< QSharedPointer< RegisterBase > > > newRegisterData)
FieldInterface * getSubInterface() const
void setAddressUnitBits(int const &newAddressUnitbits)
Interface for editing resets.
void setResets(QSharedPointer< Field > containingField)
KACTUS2_API bool busDefinitionVLNVsMatch(VLNV const &firstDefinitionVLNV, VLNV const &secondDefinitionVLNV, LibraryInterface *library)